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