igsfb.c revision 1.10 1 1.10 uwe /* $NetBSD: igsfb.c,v 1.10 2003/05/10 16:20:23 uwe Exp $ */
2 1.1 uwe
3 1.1 uwe /*
4 1.8 uwe * Copyright (c) 2002, 2003 Valeriy E. Ushakov
5 1.1 uwe * All rights reserved.
6 1.1 uwe *
7 1.1 uwe * Redistribution and use in source and binary forms, with or without
8 1.1 uwe * modification, are permitted provided that the following conditions
9 1.1 uwe * are met:
10 1.1 uwe * 1. Redistributions of source code must retain the above copyright
11 1.1 uwe * notice, this list of conditions and the following disclaimer.
12 1.1 uwe * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 uwe * notice, this list of conditions and the following disclaimer in the
14 1.1 uwe * documentation and/or other materials provided with the distribution.
15 1.1 uwe * 3. The name of the author may not be used to endorse or promote products
16 1.1 uwe * derived from this software without specific prior written permission
17 1.1 uwe *
18 1.1 uwe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 uwe * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 uwe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 uwe * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 uwe * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 uwe * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 uwe * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 uwe * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 uwe * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 uwe * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 uwe */
29 1.1 uwe
30 1.1 uwe /*
31 1.4 uwe * Integraphics Systems IGA 168x and CyberPro series.
32 1.1 uwe */
33 1.1 uwe #include <sys/cdefs.h>
34 1.10 uwe __KERNEL_RCSID(0, "$NetBSD: igsfb.c,v 1.10 2003/05/10 16:20:23 uwe Exp $");
35 1.1 uwe
36 1.1 uwe #include <sys/param.h>
37 1.1 uwe #include <sys/systm.h>
38 1.1 uwe #include <sys/kernel.h>
39 1.1 uwe #include <sys/device.h>
40 1.1 uwe #include <sys/malloc.h>
41 1.2 uwe #include <sys/ioctl.h>
42 1.1 uwe #include <sys/buf.h>
43 1.2 uwe #include <uvm/uvm_extern.h>
44 1.1 uwe
45 1.1 uwe #include <machine/bus.h>
46 1.1 uwe
47 1.1 uwe #include <dev/wscons/wsdisplayvar.h>
48 1.8 uwe #include <dev/wscons/wsconsio.h>
49 1.8 uwe #include <dev/wsfont/wsfont.h>
50 1.1 uwe #include <dev/rasops/rasops.h>
51 1.1 uwe
52 1.1 uwe #include <dev/ic/igsfbreg.h>
53 1.1 uwe #include <dev/ic/igsfbvar.h>
54 1.1 uwe
55 1.1 uwe
56 1.8 uwe struct igsfb_devconfig igsfb_console_dc;
57 1.8 uwe
58 1.1 uwe /*
59 1.1 uwe * wsscreen
60 1.1 uwe */
61 1.1 uwe
62 1.1 uwe /* filled from rasops_info in igsfb_common_init */
63 1.1 uwe static struct wsscreen_descr igsfb_stdscreen = {
64 1.1 uwe "std", /* name */
65 1.1 uwe 0, 0, /* ncols, nrows */
66 1.1 uwe NULL, /* textops */
67 1.1 uwe 0, 0, /* fontwidth, fontheight */
68 1.1 uwe 0 /* capabilities */
69 1.1 uwe };
70 1.1 uwe
71 1.1 uwe static const struct wsscreen_descr *_igsfb_scrlist[] = {
72 1.1 uwe &igsfb_stdscreen,
73 1.1 uwe };
74 1.1 uwe
75 1.1 uwe static const struct wsscreen_list igsfb_screenlist = {
76 1.1 uwe sizeof(_igsfb_scrlist) / sizeof(struct wsscreen_descr *),
77 1.1 uwe _igsfb_scrlist
78 1.1 uwe };
79 1.1 uwe
80 1.1 uwe
81 1.1 uwe /*
82 1.1 uwe * wsdisplay_accessops
83 1.1 uwe */
84 1.1 uwe
85 1.1 uwe static int igsfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
86 1.1 uwe static paddr_t igsfb_mmap(void *, off_t, int);
87 1.1 uwe
88 1.1 uwe static int igsfb_alloc_screen(void *, const struct wsscreen_descr *,
89 1.1 uwe void **, int *, int *, long *);
90 1.1 uwe static void igsfb_free_screen(void *, void *);
91 1.1 uwe static int igsfb_show_screen(void *, void *, int,
92 1.1 uwe void (*) (void *, int, int), void *);
93 1.1 uwe
94 1.1 uwe static const struct wsdisplay_accessops igsfb_accessops = {
95 1.1 uwe igsfb_ioctl,
96 1.1 uwe igsfb_mmap,
97 1.1 uwe igsfb_alloc_screen,
98 1.1 uwe igsfb_free_screen,
99 1.1 uwe igsfb_show_screen,
100 1.1 uwe NULL /* load_font */
101 1.1 uwe };
102 1.1 uwe
103 1.1 uwe
104 1.1 uwe /*
105 1.1 uwe * internal functions
106 1.1 uwe */
107 1.8 uwe static int igsfb_init_video(struct igsfb_devconfig *);
108 1.8 uwe static void igsfb_init_cmap(struct igsfb_devconfig *);
109 1.8 uwe static u_int16_t igsfb_spread_bits_8(u_int8_t);
110 1.10 uwe static void igsfb_init_bit_table(struct igsfb_devconfig *);
111 1.8 uwe static void igsfb_init_wsdisplay(struct igsfb_devconfig *);
112 1.8 uwe
113 1.8 uwe static void igsfb_blank_screen(struct igsfb_devconfig *, int);
114 1.8 uwe static int igsfb_get_cmap(struct igsfb_devconfig *,
115 1.8 uwe struct wsdisplay_cmap *);
116 1.8 uwe static int igsfb_set_cmap(struct igsfb_devconfig *,
117 1.9 uwe const struct wsdisplay_cmap *);
118 1.8 uwe static void igsfb_update_cmap(struct igsfb_devconfig *, u_int, u_int);
119 1.8 uwe static void igsfb_set_curpos(struct igsfb_devconfig *,
120 1.9 uwe const struct wsdisplay_curpos *);
121 1.8 uwe static void igsfb_update_curpos(struct igsfb_devconfig *);
122 1.8 uwe static int igsfb_get_cursor(struct igsfb_devconfig *,
123 1.1 uwe struct wsdisplay_cursor *);
124 1.8 uwe static int igsfb_set_cursor(struct igsfb_devconfig *,
125 1.9 uwe const struct wsdisplay_cursor *);
126 1.8 uwe static void igsfb_update_cursor(struct igsfb_devconfig *, u_int);
127 1.8 uwe static void igsfb_convert_cursor_data(struct igsfb_devconfig *,
128 1.8 uwe u_int, u_int);
129 1.8 uwe
130 1.8 uwe
131 1.8 uwe int
132 1.8 uwe igsfb_cnattach_subr(dc)
133 1.8 uwe struct igsfb_devconfig *dc;
134 1.8 uwe {
135 1.8 uwe struct rasops_info *ri;
136 1.8 uwe long defattr;
137 1.1 uwe
138 1.8 uwe KASSERT(dc == &igsfb_console_dc);
139 1.8 uwe
140 1.8 uwe igsfb_init_video(dc);
141 1.8 uwe igsfb_init_wsdisplay(dc);
142 1.1 uwe
143 1.8 uwe ri = &dc->dc_ri;
144 1.8 uwe (*ri->ri_ops.allocattr)(ri,
145 1.8 uwe WSCOL_BLACK, /* fg */
146 1.8 uwe WSCOL_BLACK, /* bg */
147 1.8 uwe 0, /* wsattrs */
148 1.8 uwe &defattr);
149 1.8 uwe
150 1.8 uwe wsdisplay_cnattach(&igsfb_stdscreen,
151 1.8 uwe ri, /* emulcookie */
152 1.8 uwe 0, 0, /* cursor position */
153 1.8 uwe defattr);
154 1.8 uwe return (0);
155 1.8 uwe }
156 1.1 uwe
157 1.1 uwe
158 1.1 uwe /*
159 1.1 uwe * Finish off the attach. Bus specific attach method should have
160 1.8 uwe * enabled io and memory accesses and mapped io (and cop?) registers.
161 1.1 uwe */
162 1.1 uwe void
163 1.8 uwe igsfb_attach_subr(sc, isconsole)
164 1.1 uwe struct igsfb_softc *sc;
165 1.1 uwe int isconsole;
166 1.1 uwe {
167 1.8 uwe struct igsfb_devconfig *dc = sc->sc_dc;
168 1.8 uwe struct wsemuldisplaydev_attach_args waa;
169 1.8 uwe
170 1.8 uwe KASSERT(dc != NULL);
171 1.8 uwe
172 1.8 uwe if (!isconsole) {
173 1.8 uwe igsfb_init_video(dc);
174 1.8 uwe igsfb_init_wsdisplay(dc);
175 1.8 uwe }
176 1.8 uwe
177 1.8 uwe printf("%s: %dMB, %s%dx%d, %dbpp\n",
178 1.8 uwe sc->sc_dev.dv_xname,
179 1.8 uwe (u_int32_t)(dc->dc_vmemsz >> 20),
180 1.8 uwe (dc->dc_hwflags & IGSFB_HW_BSWAP)
181 1.8 uwe ? (dc->dc_hwflags & IGSFB_HW_BE_SELECT)
182 1.8 uwe ? "hardware bswap, " : "software bswap, "
183 1.8 uwe : "",
184 1.8 uwe dc->dc_width, dc->dc_height, dc->dc_depth);
185 1.8 uwe
186 1.8 uwe /* attach wsdisplay */
187 1.8 uwe waa.console = isconsole;
188 1.8 uwe waa.scrdata = &igsfb_screenlist;
189 1.8 uwe waa.accessops = &igsfb_accessops;
190 1.8 uwe waa.accesscookie = dc;
191 1.8 uwe
192 1.8 uwe config_found(&sc->sc_dev, &waa, wsemuldisplaydevprint);
193 1.8 uwe }
194 1.8 uwe
195 1.8 uwe
196 1.8 uwe static int
197 1.8 uwe igsfb_init_video(dc)
198 1.8 uwe struct igsfb_devconfig *dc;
199 1.8 uwe {
200 1.4 uwe bus_space_handle_t tmph;
201 1.4 uwe u_int8_t *p;
202 1.4 uwe int need_bswap;
203 1.8 uwe bus_addr_t fbaddr, craddr;
204 1.1 uwe off_t croffset;
205 1.1 uwe u_int8_t busctl, curctl;
206 1.1 uwe
207 1.8 uwe /* Total amount of video memory. */
208 1.8 uwe busctl = igs_ext_read(dc->dc_iot, dc->dc_ioh, IGS_EXT_BUS_CTL);
209 1.1 uwe if (busctl & 0x2)
210 1.8 uwe dc->dc_vmemsz = 4;
211 1.1 uwe else if (busctl & 0x1)
212 1.8 uwe dc->dc_vmemsz = 2;
213 1.1 uwe else
214 1.8 uwe dc->dc_vmemsz = 1;
215 1.8 uwe dc->dc_vmemsz <<= 20; /* megabytes -> bytes */
216 1.4 uwe
217 1.4 uwe /*
218 1.8 uwe * Check for endianness mismatch by writing a word at the end of
219 1.8 uwe * the video memory (off-screen) and reading it back byte-by-byte.
220 1.4 uwe */
221 1.8 uwe if (bus_space_map(dc->dc_memt,
222 1.8 uwe dc->dc_memaddr + dc->dc_vmemsz - sizeof(u_int32_t),
223 1.4 uwe sizeof(u_int32_t),
224 1.8 uwe dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
225 1.4 uwe &tmph) != 0)
226 1.4 uwe {
227 1.4 uwe printf("unable to map video memory for endianness test\n");
228 1.8 uwe return (1);
229 1.4 uwe }
230 1.4 uwe
231 1.8 uwe p = bus_space_vaddr(dc->dc_memt, tmph);
232 1.4 uwe #if BYTE_ORDER == BIG_ENDIAN
233 1.4 uwe *((u_int32_t *)p) = 0x12345678;
234 1.4 uwe #else
235 1.4 uwe *((u_int32_t *)p) = 0x78563412;
236 1.4 uwe #endif
237 1.4 uwe if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)
238 1.4 uwe need_bswap = 0;
239 1.4 uwe else
240 1.4 uwe need_bswap = 1;
241 1.4 uwe
242 1.8 uwe bus_space_unmap(dc->dc_memt, tmph, sizeof(u_int32_t));
243 1.4 uwe
244 1.4 uwe /*
245 1.4 uwe * On CyberPro we can use magic bswap bit in linear address.
246 1.4 uwe */
247 1.8 uwe fbaddr = dc->dc_memaddr;
248 1.8 uwe if (need_bswap) {
249 1.8 uwe dc->dc_hwflags |= IGSFB_HW_BSWAP;
250 1.8 uwe if (dc->dc_id >= 0x2000) {
251 1.8 uwe dc->dc_hwflags |= IGSFB_HW_BE_SELECT;
252 1.4 uwe fbaddr |= IGS_MEM_BE_SELECT;
253 1.4 uwe }
254 1.8 uwe }
255 1.8 uwe
256 1.8 uwe /*
257 1.8 uwe * XXX: TODO: make it possible to select the desired video mode.
258 1.8 uwe * For now - hardcode to 1024x768/8bpp. This is what Krups OFW uses.
259 1.8 uwe */
260 1.8 uwe igsfb_hw_setup(dc);
261 1.8 uwe
262 1.8 uwe dc->dc_width = 1024;
263 1.8 uwe dc->dc_height = 768;
264 1.8 uwe dc->dc_depth = 8;
265 1.1 uwe
266 1.1 uwe /*
267 1.8 uwe * Don't map in all N megs, just the amount we need for the wsscreen.
268 1.1 uwe */
269 1.8 uwe dc->dc_fbsz = dc->dc_width * dc->dc_height; /* XXX: 8bpp specific */
270 1.8 uwe if (bus_space_map(dc->dc_memt, fbaddr, dc->dc_fbsz,
271 1.8 uwe dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
272 1.8 uwe &dc->dc_fbh) != 0)
273 1.1 uwe {
274 1.8 uwe bus_space_unmap(dc->dc_iot, dc->dc_ioh, IGS_REG_SIZE);
275 1.1 uwe printf("unable to map framebuffer\n");
276 1.8 uwe return (1);
277 1.1 uwe }
278 1.1 uwe
279 1.8 uwe igsfb_init_cmap(dc);
280 1.8 uwe
281 1.1 uwe /*
282 1.8 uwe * 1KB for cursor sprite data at the very end of the video memory.
283 1.1 uwe */
284 1.8 uwe croffset = dc->dc_vmemsz - IGS_CURSOR_DATA_SIZE;
285 1.4 uwe craddr = fbaddr + croffset;
286 1.8 uwe if (bus_space_map(dc->dc_memt, craddr, IGS_CURSOR_DATA_SIZE,
287 1.8 uwe dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
288 1.8 uwe &dc->dc_crh) != 0)
289 1.1 uwe {
290 1.8 uwe bus_space_unmap(dc->dc_iot, dc->dc_ioh, IGS_REG_SIZE);
291 1.8 uwe bus_space_unmap(dc->dc_memt, dc->dc_fbh, dc->dc_fbsz);
292 1.1 uwe printf("unable to map cursor sprite region\n");
293 1.8 uwe return (1);
294 1.1 uwe }
295 1.1 uwe
296 1.1 uwe /*
297 1.8 uwe * Tell the device where cursor sprite data are located in the
298 1.8 uwe * linear space (it takes data offset in 1KB units).
299 1.1 uwe */
300 1.8 uwe croffset >>= 10; /* bytes -> kilobytes */
301 1.8 uwe igs_ext_write(dc->dc_iot, dc->dc_ioh,
302 1.1 uwe IGS_EXT_SPRITE_DATA_LO, croffset & 0xff);
303 1.8 uwe igs_ext_write(dc->dc_iot, dc->dc_ioh,
304 1.1 uwe IGS_EXT_SPRITE_DATA_HI, (croffset >> 8) & 0xf);
305 1.1 uwe
306 1.10 uwe /* init the bit expansion table for cursor sprite data conversion */
307 1.10 uwe igsfb_init_bit_table(dc);
308 1.8 uwe
309 1.8 uwe /* XXX: fill dc_cursor and use igsfb_update_cursor() instead? */
310 1.8 uwe memset(&dc->dc_cursor, 0, sizeof(struct igs_hwcursor));
311 1.8 uwe memset(bus_space_vaddr(dc->dc_memt, dc->dc_crh),
312 1.8 uwe /* transparent */ 0xaa, IGS_CURSOR_DATA_SIZE);
313 1.1 uwe
314 1.8 uwe curctl = igs_ext_read(dc->dc_iot, dc->dc_ioh, IGS_EXT_SPRITE_CTL);
315 1.1 uwe curctl |= IGS_EXT_SPRITE_64x64;
316 1.1 uwe curctl &= ~IGS_EXT_SPRITE_VISIBLE;
317 1.8 uwe igs_ext_write(dc->dc_iot, dc->dc_ioh, IGS_EXT_SPRITE_CTL, curctl);
318 1.8 uwe dc->dc_curenb = 0;
319 1.1 uwe
320 1.8 uwe /* make sure screen is not blanked */
321 1.8 uwe dc->dc_blanked = 0;
322 1.8 uwe igsfb_blank_screen(dc, dc->dc_blanked);
323 1.1 uwe
324 1.8 uwe return (0);
325 1.1 uwe }
326 1.1 uwe
327 1.1 uwe
328 1.8 uwe static void
329 1.8 uwe igsfb_init_cmap(dc)
330 1.8 uwe struct igsfb_devconfig *dc;
331 1.4 uwe {
332 1.8 uwe bus_space_tag_t iot = dc->dc_iot;
333 1.8 uwe bus_space_handle_t ioh = dc->dc_ioh;
334 1.8 uwe const u_int8_t *p;
335 1.8 uwe int i;
336 1.4 uwe
337 1.8 uwe p = rasops_cmap; /* "ANSI" color map */
338 1.4 uwe
339 1.8 uwe /* init software copy */
340 1.8 uwe for (i = 0; i < IGS_CMAP_SIZE; ++i, p += 3) {
341 1.8 uwe dc->dc_cmap.r[i] = p[0];
342 1.8 uwe dc->dc_cmap.g[i] = p[1];
343 1.8 uwe dc->dc_cmap.b[i] = p[2];
344 1.8 uwe }
345 1.4 uwe
346 1.8 uwe /* propagate to the device */
347 1.8 uwe igsfb_update_cmap(dc, 0, IGS_CMAP_SIZE);
348 1.1 uwe
349 1.8 uwe /* set overscan color (XXX: use defattr's background) */
350 1.8 uwe igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_RED, 0);
351 1.8 uwe igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_GREEN, 0);
352 1.8 uwe igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_BLUE, 0);
353 1.1 uwe }
354 1.1 uwe
355 1.8 uwe
356 1.1 uwe static void
357 1.8 uwe igsfb_init_wsdisplay(dc)
358 1.8 uwe struct igsfb_devconfig *dc;
359 1.1 uwe {
360 1.8 uwe struct rasops_info *ri;
361 1.1 uwe int wsfcookie;
362 1.1 uwe
363 1.8 uwe ri = &dc->dc_ri;
364 1.8 uwe ri->ri_hw = dc;
365 1.1 uwe
366 1.1 uwe ri->ri_flg = RI_CENTER | RI_CLEAR;
367 1.8 uwe if (IGSFB_HW_SOFT_BSWAP(dc))
368 1.1 uwe ri->ri_flg |= RI_BSWAP;
369 1.1 uwe
370 1.8 uwe ri->ri_depth = dc->dc_depth;
371 1.8 uwe ri->ri_width = dc->dc_width;
372 1.8 uwe ri->ri_height = dc->dc_height;
373 1.6 uwe
374 1.8 uwe ri->ri_stride = dc->dc_width; /* XXX: 8bpp specific */
375 1.8 uwe ri->ri_bits = (u_char *)dc->dc_fbh;
376 1.1 uwe
377 1.1 uwe /*
378 1.1 uwe * Initialize wsfont related stuff.
379 1.1 uwe */
380 1.1 uwe wsfont_init();
381 1.1 uwe
382 1.1 uwe /* prefer gallant that is identical to the one the prom uses */
383 1.1 uwe wsfcookie = wsfont_find("Gallant", 12, 22, 0,
384 1.1 uwe WSDISPLAY_FONTORDER_L2R,
385 1.1 uwe WSDISPLAY_FONTORDER_L2R);
386 1.1 uwe if (wsfcookie <= 0) {
387 1.1 uwe #ifdef DIAGNOSTIC
388 1.8 uwe printf("unable to find font Gallant 12x22\n");
389 1.1 uwe #endif
390 1.8 uwe wsfcookie = wsfont_find(NULL, 0, 0, 0, /* any font at all? */
391 1.1 uwe WSDISPLAY_FONTORDER_L2R,
392 1.1 uwe WSDISPLAY_FONTORDER_L2R);
393 1.1 uwe }
394 1.1 uwe
395 1.1 uwe if (wsfcookie <= 0) {
396 1.8 uwe printf("unable to find any fonts\n");
397 1.1 uwe return;
398 1.1 uwe }
399 1.1 uwe
400 1.1 uwe if (wsfont_lock(wsfcookie, &ri->ri_font) != 0) {
401 1.8 uwe printf("unable to lock font\n");
402 1.1 uwe return;
403 1.1 uwe }
404 1.1 uwe ri->ri_wsfcookie = wsfcookie;
405 1.1 uwe
406 1.1 uwe
407 1.8 uwe /* XXX: TODO: compute term size based on font dimensions. */
408 1.1 uwe rasops_init(ri, 34, 80);
409 1.1 uwe
410 1.1 uwe igsfb_stdscreen.nrows = ri->ri_rows;
411 1.1 uwe igsfb_stdscreen.ncols = ri->ri_cols;
412 1.1 uwe igsfb_stdscreen.textops = &ri->ri_ops;
413 1.1 uwe igsfb_stdscreen.capabilities = ri->ri_caps;
414 1.1 uwe }
415 1.1 uwe
416 1.1 uwe
417 1.1 uwe /*
418 1.8 uwe * Spread a byte (abcd.efgh) into two (0a0b.0c0d 0e0f.0g0h).
419 1.10 uwe * Helper function for igsfb_init_bit_table().
420 1.8 uwe */
421 1.8 uwe static u_int16_t
422 1.8 uwe igsfb_spread_bits_8(b)
423 1.8 uwe u_int8_t b;
424 1.8 uwe {
425 1.8 uwe u_int16_t s = b;
426 1.8 uwe
427 1.8 uwe s = ((s & 0x00f0) << 4) | (s & 0x000f);
428 1.8 uwe s = ((s & 0x0c0c) << 2) | (s & 0x0303);
429 1.8 uwe s = ((s & 0x2222) << 1) | (s & 0x1111);
430 1.8 uwe return (s);
431 1.8 uwe }
432 1.8 uwe
433 1.8 uwe
434 1.8 uwe /*
435 1.8 uwe * Cursor sprite data are in 2bpp. Incoming image/mask are in 1bpp.
436 1.10 uwe * Prebuild the table to expand 1bpp->2bpp, with bswapping if neccessary.
437 1.8 uwe */
438 1.8 uwe static void
439 1.10 uwe igsfb_init_bit_table(dc)
440 1.8 uwe struct igsfb_devconfig *dc;
441 1.8 uwe {
442 1.10 uwe u_int16_t *expand = dc->dc_bexpand;
443 1.8 uwe int need_bswap = IGSFB_HW_SOFT_BSWAP(dc);
444 1.10 uwe u_int16_t s;
445 1.8 uwe u_int i;
446 1.8 uwe
447 1.8 uwe for (i = 0; i < 256; ++i) {
448 1.10 uwe s = igsfb_spread_bits_8(i);
449 1.10 uwe expand[i] = need_bswap ? bswap16(s) : s;
450 1.8 uwe }
451 1.8 uwe }
452 1.8 uwe
453 1.8 uwe
454 1.8 uwe /*
455 1.1 uwe * wsdisplay_accessops: mmap()
456 1.4 uwe * XXX: allow mmapping i/o mapped i/o regs if INSECURE???
457 1.1 uwe */
458 1.1 uwe static paddr_t
459 1.1 uwe igsfb_mmap(v, offset, prot)
460 1.1 uwe void *v;
461 1.1 uwe off_t offset;
462 1.1 uwe int prot;
463 1.1 uwe {
464 1.8 uwe struct igsfb_devconfig *dc = v;
465 1.1 uwe
466 1.8 uwe if (offset >= dc->dc_memsz || offset < 0)
467 1.1 uwe return (-1);
468 1.1 uwe
469 1.8 uwe return (bus_space_mmap(dc->dc_memt, dc->dc_memaddr, offset, prot,
470 1.8 uwe dc->dc_memflags | BUS_SPACE_MAP_LINEAR));
471 1.1 uwe }
472 1.1 uwe
473 1.1 uwe
474 1.1 uwe /*
475 1.1 uwe * wsdisplay_accessops: ioctl()
476 1.1 uwe */
477 1.1 uwe static int
478 1.1 uwe igsfb_ioctl(v, cmd, data, flag, p)
479 1.1 uwe void *v;
480 1.1 uwe u_long cmd;
481 1.1 uwe caddr_t data;
482 1.1 uwe int flag;
483 1.1 uwe struct proc *p;
484 1.1 uwe {
485 1.8 uwe struct igsfb_devconfig *dc = v;
486 1.8 uwe struct rasops_info *ri;
487 1.1 uwe int turnoff;
488 1.1 uwe
489 1.1 uwe switch (cmd) {
490 1.1 uwe
491 1.1 uwe case WSDISPLAYIO_GTYPE:
492 1.1 uwe *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
493 1.1 uwe return (0);
494 1.1 uwe
495 1.1 uwe case WSDISPLAYIO_GINFO:
496 1.8 uwe ri = &dc->dc_ri;
497 1.1 uwe #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
498 1.1 uwe wsd_fbip->height = ri->ri_height;
499 1.1 uwe wsd_fbip->width = ri->ri_width;
500 1.1 uwe wsd_fbip->depth = ri->ri_depth;
501 1.1 uwe wsd_fbip->cmsize = IGS_CMAP_SIZE;
502 1.1 uwe #undef wsd_fbip
503 1.1 uwe return (0);
504 1.1 uwe
505 1.1 uwe case WSDISPLAYIO_GVIDEO:
506 1.8 uwe *(u_int *)data = dc->dc_blanked ?
507 1.1 uwe WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
508 1.1 uwe return (0);
509 1.1 uwe
510 1.1 uwe case WSDISPLAYIO_SVIDEO:
511 1.1 uwe turnoff = (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF);
512 1.8 uwe if (dc->dc_blanked != turnoff) {
513 1.8 uwe dc->dc_blanked = turnoff;
514 1.8 uwe igsfb_blank_screen(dc, dc->dc_blanked);
515 1.1 uwe }
516 1.1 uwe return (0);
517 1.1 uwe
518 1.1 uwe case WSDISPLAYIO_GETCMAP:
519 1.8 uwe return (igsfb_get_cmap(dc, (struct wsdisplay_cmap *)data));
520 1.1 uwe
521 1.1 uwe case WSDISPLAYIO_PUTCMAP:
522 1.8 uwe return (igsfb_set_cmap(dc, (struct wsdisplay_cmap *)data));
523 1.1 uwe
524 1.1 uwe case WSDISPLAYIO_GCURMAX:
525 1.1 uwe ((struct wsdisplay_curpos *)data)->x = IGS_CURSOR_MAX_SIZE;
526 1.1 uwe ((struct wsdisplay_curpos *)data)->y = IGS_CURSOR_MAX_SIZE;
527 1.1 uwe return (0);
528 1.1 uwe
529 1.1 uwe case WSDISPLAYIO_GCURPOS:
530 1.8 uwe *(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
531 1.1 uwe return (0);
532 1.1 uwe
533 1.1 uwe case WSDISPLAYIO_SCURPOS:
534 1.8 uwe igsfb_set_curpos(dc, (struct wsdisplay_curpos *)data);
535 1.1 uwe return (0);
536 1.1 uwe
537 1.1 uwe case WSDISPLAYIO_GCURSOR:
538 1.8 uwe return (igsfb_get_cursor(dc, (struct wsdisplay_cursor *)data));
539 1.1 uwe
540 1.1 uwe case WSDISPLAYIO_SCURSOR:
541 1.8 uwe return (igsfb_set_cursor(dc, (struct wsdisplay_cursor *)data));
542 1.1 uwe }
543 1.1 uwe
544 1.1 uwe return (EPASSTHROUGH);
545 1.1 uwe }
546 1.1 uwe
547 1.1 uwe
548 1.1 uwe /*
549 1.1 uwe * wsdisplay_accessops: ioctl(WSDISPLAYIO_SVIDEO)
550 1.1 uwe */
551 1.1 uwe static void
552 1.8 uwe igsfb_blank_screen(dc, blank)
553 1.8 uwe struct igsfb_devconfig *dc;
554 1.1 uwe int blank;
555 1.1 uwe {
556 1.1 uwe
557 1.8 uwe igs_ext_write(dc->dc_iot, dc->dc_ioh,
558 1.1 uwe IGS_EXT_SYNC_CTL,
559 1.1 uwe blank ? IGS_EXT_SYNC_H0 | IGS_EXT_SYNC_V0
560 1.1 uwe : 0);
561 1.1 uwe }
562 1.1 uwe
563 1.1 uwe
564 1.1 uwe /*
565 1.1 uwe * wsdisplay_accessops: ioctl(WSDISPLAYIO_GETCMAP)
566 1.8 uwe * Served from the software cmap copy.
567 1.1 uwe */
568 1.1 uwe static int
569 1.8 uwe igsfb_get_cmap(dc, p)
570 1.8 uwe struct igsfb_devconfig *dc;
571 1.1 uwe struct wsdisplay_cmap *p;
572 1.1 uwe {
573 1.1 uwe u_int index = p->index, count = p->count;
574 1.1 uwe
575 1.5 itojun if (index >= IGS_CMAP_SIZE || count > IGS_CMAP_SIZE - index)
576 1.1 uwe return (EINVAL);
577 1.1 uwe
578 1.1 uwe if (!uvm_useracc(p->red, count, B_WRITE) ||
579 1.1 uwe !uvm_useracc(p->green, count, B_WRITE) ||
580 1.1 uwe !uvm_useracc(p->blue, count, B_WRITE))
581 1.1 uwe return (EFAULT);
582 1.1 uwe
583 1.8 uwe copyout(&dc->dc_cmap.r[index], p->red, count);
584 1.8 uwe copyout(&dc->dc_cmap.g[index], p->green, count);
585 1.8 uwe copyout(&dc->dc_cmap.b[index], p->blue, count);
586 1.1 uwe
587 1.1 uwe return (0);
588 1.1 uwe }
589 1.1 uwe
590 1.1 uwe
591 1.1 uwe /*
592 1.1 uwe * wsdisplay_accessops: ioctl(WSDISPLAYIO_SETCMAP)
593 1.8 uwe * Set the software cmap copy and propagate changed range to the device.
594 1.1 uwe */
595 1.1 uwe static int
596 1.8 uwe igsfb_set_cmap(dc, p)
597 1.8 uwe struct igsfb_devconfig *dc;
598 1.9 uwe const struct wsdisplay_cmap *p;
599 1.1 uwe {
600 1.1 uwe u_int index = p->index, count = p->count;
601 1.1 uwe
602 1.5 itojun if (index >= IGS_CMAP_SIZE || count > IGS_CMAP_SIZE - index)
603 1.1 uwe return (EINVAL);
604 1.1 uwe
605 1.1 uwe if (!uvm_useracc(p->red, count, B_READ) ||
606 1.1 uwe !uvm_useracc(p->green, count, B_READ) ||
607 1.1 uwe !uvm_useracc(p->blue, count, B_READ))
608 1.1 uwe return (EFAULT);
609 1.1 uwe
610 1.8 uwe copyin(p->red, &dc->dc_cmap.r[index], count);
611 1.8 uwe copyin(p->green, &dc->dc_cmap.g[index], count);
612 1.8 uwe copyin(p->blue, &dc->dc_cmap.b[index], count);
613 1.1 uwe
614 1.8 uwe igsfb_update_cmap(dc, p->index, p->count);
615 1.1 uwe
616 1.1 uwe return (0);
617 1.1 uwe }
618 1.1 uwe
619 1.1 uwe
620 1.1 uwe /*
621 1.8 uwe * Propagate specified part of the software cmap copy to the device.
622 1.1 uwe */
623 1.1 uwe static void
624 1.8 uwe igsfb_update_cmap(dc, index, count)
625 1.8 uwe struct igsfb_devconfig *dc;
626 1.1 uwe u_int index, count;
627 1.1 uwe {
628 1.1 uwe bus_space_tag_t t;
629 1.1 uwe bus_space_handle_t h;
630 1.1 uwe u_int last, i;
631 1.1 uwe
632 1.1 uwe if (index >= IGS_CMAP_SIZE)
633 1.1 uwe return;
634 1.1 uwe
635 1.1 uwe last = index + count;
636 1.1 uwe if (last > IGS_CMAP_SIZE)
637 1.1 uwe last = IGS_CMAP_SIZE;
638 1.1 uwe
639 1.8 uwe t = dc->dc_iot;
640 1.8 uwe h = dc->dc_ioh;
641 1.1 uwe
642 1.1 uwe /* start palette writing, index is autoincremented by hardware */
643 1.1 uwe bus_space_write_1(t, h, IGS_DAC_PEL_WRITE_IDX, index);
644 1.1 uwe
645 1.1 uwe for (i = index; i < last; ++i) {
646 1.8 uwe bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.r[i]);
647 1.8 uwe bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.g[i]);
648 1.8 uwe bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.b[i]);
649 1.1 uwe }
650 1.1 uwe }
651 1.1 uwe
652 1.1 uwe
653 1.1 uwe /*
654 1.1 uwe * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURPOS)
655 1.1 uwe */
656 1.1 uwe static void
657 1.8 uwe igsfb_set_curpos(dc, curpos)
658 1.8 uwe struct igsfb_devconfig *dc;
659 1.9 uwe const struct wsdisplay_curpos *curpos;
660 1.1 uwe {
661 1.8 uwe struct rasops_info *ri = &dc->dc_ri;
662 1.9 uwe u_int x = curpos->x, y = curpos->y;
663 1.9 uwe
664 1.9 uwe if (x >= ri->ri_width)
665 1.9 uwe x = ri->ri_width - 1;
666 1.9 uwe if (y >= ri->ri_height)
667 1.9 uwe y = ri->ri_height - 1;
668 1.1 uwe
669 1.8 uwe dc->dc_cursor.cc_pos.x = x;
670 1.8 uwe dc->dc_cursor.cc_pos.y = y;
671 1.1 uwe
672 1.8 uwe igsfb_update_curpos(dc);
673 1.1 uwe }
674 1.1 uwe
675 1.1 uwe
676 1.1 uwe static void
677 1.8 uwe igsfb_update_curpos(dc)
678 1.8 uwe struct igsfb_devconfig *dc;
679 1.1 uwe {
680 1.1 uwe bus_space_tag_t t;
681 1.1 uwe bus_space_handle_t h;
682 1.1 uwe int x, xoff, y, yoff;
683 1.1 uwe
684 1.1 uwe xoff = 0;
685 1.8 uwe x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
686 1.1 uwe if (x < 0) {
687 1.8 uwe xoff = -x;
688 1.1 uwe x = 0;
689 1.1 uwe }
690 1.1 uwe
691 1.1 uwe yoff = 0;
692 1.8 uwe y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
693 1.1 uwe if (y < 0) {
694 1.8 uwe yoff = -y;
695 1.1 uwe y = 0;
696 1.1 uwe }
697 1.1 uwe
698 1.8 uwe t = dc->dc_iot;
699 1.8 uwe h = dc->dc_ioh;
700 1.1 uwe
701 1.1 uwe igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_LO, x & 0xff);
702 1.1 uwe igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_HI, (x >> 8) & 0x07);
703 1.1 uwe igs_ext_write(t, h, IGS_EXT_SPRITE_HPRESET, xoff & 0x3f);
704 1.1 uwe
705 1.1 uwe igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_LO, y & 0xff);
706 1.1 uwe igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_HI, (y >> 8) & 0x07);
707 1.1 uwe igs_ext_write(t, h, IGS_EXT_SPRITE_VPRESET, yoff & 0x3f);
708 1.1 uwe }
709 1.1 uwe
710 1.1 uwe
711 1.1 uwe /*
712 1.1 uwe * wsdisplay_accessops: ioctl(WSDISPLAYIO_GCURSOR)
713 1.1 uwe */
714 1.1 uwe static int
715 1.8 uwe igsfb_get_cursor(dc, p)
716 1.8 uwe struct igsfb_devconfig *dc;
717 1.1 uwe struct wsdisplay_cursor *p;
718 1.1 uwe {
719 1.1 uwe
720 1.1 uwe /* XXX: TODO */
721 1.1 uwe return (0);
722 1.1 uwe }
723 1.1 uwe
724 1.1 uwe
725 1.1 uwe /*
726 1.1 uwe * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURSOR)
727 1.1 uwe */
728 1.1 uwe static int
729 1.8 uwe igsfb_set_cursor(dc, p)
730 1.8 uwe struct igsfb_devconfig *dc;
731 1.9 uwe const struct wsdisplay_cursor *p;
732 1.1 uwe {
733 1.1 uwe struct igs_hwcursor *cc;
734 1.9 uwe struct wsdisplay_curpos pos, hot;
735 1.1 uwe u_int v, index, count, icount, iwidth;
736 1.1 uwe
737 1.8 uwe cc = &dc->dc_cursor;
738 1.1 uwe v = p->which;
739 1.1 uwe
740 1.9 uwe /* verify that the new cursor colormap is valid */
741 1.1 uwe if (v & WSDISPLAY_CURSOR_DOCMAP) {
742 1.1 uwe index = p->cmap.index;
743 1.1 uwe count = p->cmap.count;
744 1.1 uwe if (index >= 2 || (index + count) > 2)
745 1.1 uwe return (EINVAL);
746 1.9 uwe
747 1.1 uwe if (!uvm_useracc(p->cmap.red, count, B_READ)
748 1.1 uwe || !uvm_useracc(p->cmap.green, count, B_READ)
749 1.1 uwe || !uvm_useracc(p->cmap.blue, count, B_READ))
750 1.1 uwe return (EFAULT);
751 1.1 uwe }
752 1.1 uwe
753 1.9 uwe /* verify that the new cursor data are valid */
754 1.1 uwe if (v & WSDISPLAY_CURSOR_DOSHAPE) {
755 1.1 uwe if (p->size.x > IGS_CURSOR_MAX_SIZE
756 1.1 uwe || p->size.y > IGS_CURSOR_MAX_SIZE)
757 1.1 uwe return (EINVAL);
758 1.1 uwe
759 1.1 uwe iwidth = (p->size.x + 7) >> 3; /* bytes per scan line */
760 1.1 uwe icount = iwidth * p->size.y;
761 1.1 uwe if (!uvm_useracc(p->image, icount, B_READ)
762 1.1 uwe || !uvm_useracc(p->mask, icount, B_READ))
763 1.1 uwe return (EFAULT);
764 1.1 uwe }
765 1.1 uwe
766 1.9 uwe /* enforce that the position is within screen bounds */
767 1.9 uwe if (v & WSDISPLAY_CURSOR_DOPOS) {
768 1.9 uwe struct rasops_info *ri = &dc->dc_ri;
769 1.9 uwe
770 1.9 uwe pos = p->pos; /* local copy we can write to */
771 1.9 uwe if (pos.x >= ri->ri_width)
772 1.9 uwe pos.x = ri->ri_width - 1;
773 1.9 uwe if (pos.y >= ri->ri_height)
774 1.9 uwe pos.y = ri->ri_height - 1;
775 1.9 uwe }
776 1.9 uwe
777 1.9 uwe /* enforce that the hot spot is within sprite bounds */
778 1.9 uwe if (v & WSDISPLAY_CURSOR_DOHOT)
779 1.9 uwe hot = p->hot; /* local copy we can write to */
780 1.9 uwe
781 1.9 uwe if (v & (WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOSHAPE)) {
782 1.9 uwe const struct wsdisplay_curpos *nsize;
783 1.9 uwe struct wsdisplay_curpos *nhot;
784 1.1 uwe
785 1.9 uwe nsize = (v & WSDISPLAY_CURSOR_DOSHAPE) ?
786 1.9 uwe &p->size : &cc->cc_size;
787 1.9 uwe nhot = (v & WSDISPLAY_CURSOR_DOHOT) ? &hot : &cc->cc_hot;
788 1.1 uwe
789 1.9 uwe if (nhot->x >= nsize->x)
790 1.9 uwe nhot->x = nsize->x - 1;
791 1.9 uwe if (nhot->y >= nsize->y)
792 1.9 uwe nhot->y = nsize->y - 1;
793 1.9 uwe }
794 1.9 uwe
795 1.9 uwe
796 1.9 uwe /* arguments verified, copy data to the driver's cursor info */
797 1.1 uwe if (v & WSDISPLAY_CURSOR_DOCUR)
798 1.8 uwe dc->dc_curenb = p->enable;
799 1.1 uwe
800 1.1 uwe if (v & WSDISPLAY_CURSOR_DOPOS)
801 1.9 uwe cc->cc_pos = pos; /* local copy, possibly corrected */
802 1.1 uwe
803 1.1 uwe if (v & WSDISPLAY_CURSOR_DOHOT)
804 1.9 uwe cc->cc_hot = hot; /* local copy, possibly corrected */
805 1.1 uwe
806 1.1 uwe if (v & WSDISPLAY_CURSOR_DOCMAP) {
807 1.1 uwe copyin(p->cmap.red, &cc->cc_color[index], count);
808 1.1 uwe copyin(p->cmap.green, &cc->cc_color[index + 2], count);
809 1.1 uwe copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
810 1.1 uwe }
811 1.1 uwe
812 1.1 uwe if (v & WSDISPLAY_CURSOR_DOSHAPE) {
813 1.1 uwe u_int trailing_bits;
814 1.1 uwe
815 1.1 uwe copyin(p->image, cc->cc_image, icount);
816 1.1 uwe copyin(p->mask, cc->cc_mask, icount);
817 1.1 uwe cc->cc_size = p->size;
818 1.1 uwe
819 1.1 uwe /* clear trailing bits in the "partial" mask bytes */
820 1.1 uwe trailing_bits = p->size.x & 0x07;
821 1.1 uwe if (trailing_bits != 0) {
822 1.1 uwe const u_int cutmask = ~((~0) << trailing_bits);
823 1.1 uwe u_char *mp;
824 1.1 uwe u_int i;
825 1.1 uwe
826 1.1 uwe mp = cc->cc_mask + iwidth - 1;
827 1.1 uwe for (i = 0; i < p->size.y; ++i) {
828 1.1 uwe *mp &= cutmask;
829 1.1 uwe mp += iwidth;
830 1.1 uwe }
831 1.1 uwe }
832 1.8 uwe igsfb_convert_cursor_data(dc, iwidth, p->size.y);
833 1.1 uwe }
834 1.1 uwe
835 1.9 uwe /* propagate changes to the device */
836 1.8 uwe igsfb_update_cursor(dc, v);
837 1.9 uwe
838 1.1 uwe return (0);
839 1.1 uwe }
840 1.1 uwe
841 1.4 uwe
842 1.1 uwe /*
843 1.1 uwe * Convert incoming 1bpp cursor image/mask into native 2bpp format.
844 1.1 uwe */
845 1.1 uwe static void
846 1.10 uwe igsfb_convert_cursor_data(dc, width, height)
847 1.8 uwe struct igsfb_devconfig *dc;
848 1.10 uwe u_int width, height;
849 1.1 uwe {
850 1.8 uwe struct igs_hwcursor *cc = &dc->dc_cursor;
851 1.10 uwe u_int16_t *expand = dc->dc_bexpand;
852 1.1 uwe u_int8_t *ip, *mp;
853 1.10 uwe u_int16_t is, ms, *dp;
854 1.1 uwe u_int line, i;
855 1.1 uwe
856 1.1 uwe /* init sprite to be all transparent */
857 1.1 uwe memset(cc->cc_sprite, 0xaa, IGS_CURSOR_DATA_SIZE);
858 1.1 uwe
859 1.1 uwe /* first scanline */
860 1.1 uwe ip = cc->cc_image;
861 1.1 uwe mp = cc->cc_mask;
862 1.1 uwe dp = cc->cc_sprite;
863 1.1 uwe
864 1.10 uwe for (line = 0; line < height; ++line) {
865 1.10 uwe for (i = 0; i < width; ++i) {
866 1.10 uwe is = expand[ip[i]]; /* image: 0 -> 00, 1 -> 01 */
867 1.10 uwe ms = expand[mp[i]]; /* mask: 0 -> 00, 1 -> 11 */
868 1.8 uwe ms |= (ms << 1);
869 1.1 uwe dp[i] = (0xaaaa & ~ms) | (is & ms);
870 1.1 uwe }
871 1.1 uwe
872 1.1 uwe /* next scanline */
873 1.10 uwe ip += width;
874 1.10 uwe mp += width;
875 1.10 uwe dp += 8; /* 64 pixels, 2bpp, 8 pixels per short = 8 shorts */
876 1.1 uwe }
877 1.1 uwe }
878 1.1 uwe
879 1.1 uwe
880 1.1 uwe /*
881 1.8 uwe * Propagate cursor changes to the device.
882 1.8 uwe * "which" is composed of WSDISPLAY_CURSOR_DO* bits.
883 1.1 uwe */
884 1.1 uwe static void
885 1.8 uwe igsfb_update_cursor(dc, which)
886 1.8 uwe struct igsfb_devconfig *dc;
887 1.1 uwe u_int which;
888 1.1 uwe {
889 1.8 uwe bus_space_tag_t iot = dc->dc_iot;
890 1.8 uwe bus_space_handle_t ioh = dc->dc_ioh;
891 1.1 uwe u_int8_t curctl;
892 1.1 uwe
893 1.1 uwe /*
894 1.1 uwe * We will need to tweak sprite control register for cursor
895 1.1 uwe * visibility and cursor color map manipualtion.
896 1.1 uwe */
897 1.1 uwe if (which & (WSDISPLAY_CURSOR_DOCUR | WSDISPLAY_CURSOR_DOCMAP)) {
898 1.1 uwe curctl = igs_ext_read(iot, ioh, IGS_EXT_SPRITE_CTL);
899 1.1 uwe }
900 1.1 uwe
901 1.1 uwe if (which & WSDISPLAY_CURSOR_DOSHAPE) {
902 1.8 uwe u_int8_t *dst = bus_space_vaddr(dc->dc_memt, dc->dc_crh);
903 1.1 uwe
904 1.1 uwe /*
905 1.1 uwe * memcpy between spaces of different endianness would
906 1.8 uwe * be ... special. We cannot be sure if memcpy gonna
907 1.1 uwe * push data in 4-byte chunks, we can't pre-bswap it,
908 1.1 uwe * so do it byte-by-byte to preserve byte ordering.
909 1.1 uwe */
910 1.8 uwe if (IGSFB_HW_SOFT_BSWAP(dc)) {
911 1.8 uwe u_int8_t *src = (u_int8_t *)dc->dc_cursor.cc_sprite;
912 1.1 uwe int i;
913 1.1 uwe
914 1.8 uwe for (i = 0; i < IGS_CURSOR_DATA_SIZE; ++i)
915 1.1 uwe *dst++ = *src++;
916 1.1 uwe } else {
917 1.8 uwe memcpy(dst, dc->dc_cursor.cc_sprite,
918 1.8 uwe IGS_CURSOR_DATA_SIZE);
919 1.1 uwe }
920 1.1 uwe }
921 1.1 uwe
922 1.1 uwe if (which & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
923 1.1 uwe /* code shared with WSDISPLAYIO_SCURPOS */
924 1.8 uwe igsfb_update_curpos(dc);
925 1.1 uwe }
926 1.1 uwe
927 1.1 uwe if (which & WSDISPLAY_CURSOR_DOCMAP) {
928 1.1 uwe u_int8_t *p;
929 1.1 uwe
930 1.1 uwe /* tell DAC we want access to the cursor palette */
931 1.1 uwe igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
932 1.4 uwe curctl | IGS_EXT_SPRITE_DAC_PEL);
933 1.1 uwe
934 1.8 uwe p = dc->dc_cursor.cc_color;
935 1.1 uwe
936 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 0);
937 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[0]);
938 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[2]);
939 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[4]);
940 1.1 uwe
941 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 1);
942 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[1]);
943 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[3]);
944 1.1 uwe bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[5]);
945 1.1 uwe
946 1.8 uwe /* restore access to the normal palette */
947 1.1 uwe igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL, curctl);
948 1.1 uwe }
949 1.1 uwe
950 1.1 uwe if (which & WSDISPLAY_CURSOR_DOCUR) {
951 1.1 uwe if ((curctl & IGS_EXT_SPRITE_VISIBLE) == 0
952 1.8 uwe && dc->dc_curenb)
953 1.1 uwe igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
954 1.1 uwe curctl | IGS_EXT_SPRITE_VISIBLE);
955 1.1 uwe else if ((curctl & IGS_EXT_SPRITE_VISIBLE) != 0
956 1.8 uwe && !dc->dc_curenb)
957 1.1 uwe igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
958 1.1 uwe curctl & ~IGS_EXT_SPRITE_VISIBLE);
959 1.1 uwe }
960 1.1 uwe }
961 1.1 uwe
962 1.1 uwe
963 1.1 uwe /*
964 1.1 uwe * wsdisplay_accessops: alloc_screen()
965 1.1 uwe */
966 1.1 uwe static int
967 1.1 uwe igsfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
968 1.1 uwe void *v;
969 1.1 uwe const struct wsscreen_descr *type;
970 1.1 uwe void **cookiep;
971 1.1 uwe int *curxp, *curyp;
972 1.1 uwe long *attrp;
973 1.1 uwe {
974 1.8 uwe struct igsfb_devconfig *dc = v;
975 1.8 uwe struct rasops_info *ri = &dc->dc_ri;
976 1.7 uwe
977 1.8 uwe if (dc->dc_nscreens > 0) /* only do single screen for now */
978 1.7 uwe return (ENOMEM);
979 1.1 uwe
980 1.8 uwe dc->dc_nscreens = 1;
981 1.7 uwe
982 1.8 uwe *cookiep = ri; /* emulcookie for igsgfb_stdscreen.textops */
983 1.8 uwe *curxp = *curyp = 0; /* cursor position */
984 1.8 uwe (*ri->ri_ops.allocattr)(ri,
985 1.8 uwe WSCOL_BLACK, /* fg */
986 1.8 uwe WSCOL_BLACK, /* bg */
987 1.8 uwe 0, /* wsattr */
988 1.8 uwe attrp);
989 1.7 uwe return (0);
990 1.1 uwe }
991 1.1 uwe
992 1.1 uwe
993 1.1 uwe /*
994 1.1 uwe * wsdisplay_accessops: free_screen()
995 1.1 uwe */
996 1.1 uwe static void
997 1.1 uwe igsfb_free_screen(v, cookie)
998 1.1 uwe void *v;
999 1.1 uwe void *cookie;
1000 1.1 uwe {
1001 1.1 uwe
1002 1.8 uwe /* XXX */
1003 1.1 uwe return;
1004 1.1 uwe }
1005 1.1 uwe
1006 1.1 uwe
1007 1.1 uwe /*
1008 1.1 uwe * wsdisplay_accessops: show_screen()
1009 1.1 uwe */
1010 1.1 uwe static int
1011 1.1 uwe igsfb_show_screen(v, cookie, waitok, cb, cbarg)
1012 1.1 uwe void *v;
1013 1.1 uwe void *cookie;
1014 1.1 uwe int waitok;
1015 1.1 uwe void (*cb)(void *, int, int);
1016 1.1 uwe void *cbarg;
1017 1.1 uwe {
1018 1.1 uwe
1019 1.8 uwe /* XXX */
1020 1.1 uwe return (0);
1021 1.1 uwe }
1022