igsfb.c revision 1.14 1 /* $NetBSD: igsfb.c,v 1.14 2003/06/24 00:13:29 uwe Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2003 Valeriy E. Ushakov
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * Integraphics Systems IGA 168x and CyberPro series.
32 */
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: igsfb.c,v 1.14 2003/06/24 00:13:29 uwe Exp $");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/device.h>
40 #include <sys/malloc.h>
41 #include <sys/ioctl.h>
42 #include <sys/buf.h>
43 #include <uvm/uvm_extern.h>
44
45 #include <machine/bus.h>
46
47 #include <dev/wscons/wsdisplayvar.h>
48 #include <dev/wscons/wsconsio.h>
49 #include <dev/wsfont/wsfont.h>
50 #include <dev/rasops/rasops.h>
51
52 #include <dev/ic/igsfbreg.h>
53 #include <dev/ic/igsfbvar.h>
54
55
56 struct igsfb_devconfig igsfb_console_dc;
57
58 /*
59 * wsscreen
60 */
61
62 /* filled from rasops_info in igsfb_common_init */
63 static struct wsscreen_descr igsfb_stdscreen = {
64 "std", /* name */
65 0, 0, /* ncols, nrows */
66 NULL, /* textops */
67 0, 0, /* fontwidth, fontheight */
68 0 /* capabilities */
69 };
70
71 static const struct wsscreen_descr *_igsfb_scrlist[] = {
72 &igsfb_stdscreen,
73 };
74
75 static const struct wsscreen_list igsfb_screenlist = {
76 sizeof(_igsfb_scrlist) / sizeof(struct wsscreen_descr *),
77 _igsfb_scrlist
78 };
79
80
81 /*
82 * wsdisplay_accessops
83 */
84
85 static int igsfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
86 static paddr_t igsfb_mmap(void *, off_t, int);
87
88 static int igsfb_alloc_screen(void *, const struct wsscreen_descr *,
89 void **, int *, int *, long *);
90 static void igsfb_free_screen(void *, void *);
91 static int igsfb_show_screen(void *, void *, int,
92 void (*) (void *, int, int), void *);
93
94 static const struct wsdisplay_accessops igsfb_accessops = {
95 igsfb_ioctl,
96 igsfb_mmap,
97 igsfb_alloc_screen,
98 igsfb_free_screen,
99 igsfb_show_screen,
100 NULL, /* load_font */
101 NULL, /* pollc */
102 NULL, /* getwschar */
103 NULL /* putwschar */
104 };
105
106
107 /*
108 * acceleration
109 */
110 static int igsfb_make_text_cursor(struct igsfb_devconfig *);
111 static void igsfb_accel_cursor(void *, int, int, int);
112
113 static int igsfb_accel_wait(struct igsfb_devconfig *);
114 static void igsfb_accel_fill(struct igsfb_devconfig *,
115 u_int32_t, u_int32_t, u_int16_t, u_int16_t);
116 static void igsfb_accel_copy(struct igsfb_devconfig *,
117 u_int32_t, u_int32_t, u_int16_t, u_int16_t);
118
119 static void igsfb_accel_copycols(void *, int, int, int, int);
120 static void igsfb_accel_erasecols(void *, int, int, int, long);
121 static void igsfb_accel_copyrows(void *, int, int, int);
122 static void igsfb_accel_eraserows(void *, int, int, long);
123 static void igsfb_accel_putchar(void *, int, int, u_int, long);
124
125
126 /*
127 * internal functions
128 */
129 static int igsfb_init_video(struct igsfb_devconfig *);
130 static void igsfb_init_cmap(struct igsfb_devconfig *);
131 static u_int16_t igsfb_spread_bits_8(u_int8_t);
132 static void igsfb_init_bit_table(struct igsfb_devconfig *);
133 static void igsfb_init_wsdisplay(struct igsfb_devconfig *);
134
135 static void igsfb_blank_screen(struct igsfb_devconfig *, int);
136 static int igsfb_get_cmap(struct igsfb_devconfig *,
137 struct wsdisplay_cmap *);
138 static int igsfb_set_cmap(struct igsfb_devconfig *,
139 const struct wsdisplay_cmap *);
140 static void igsfb_update_cmap(struct igsfb_devconfig *, u_int, u_int);
141 static void igsfb_set_curpos(struct igsfb_devconfig *,
142 const struct wsdisplay_curpos *);
143 static void igsfb_update_curpos(struct igsfb_devconfig *);
144 static int igsfb_get_cursor(struct igsfb_devconfig *,
145 struct wsdisplay_cursor *);
146 static int igsfb_set_cursor(struct igsfb_devconfig *,
147 const struct wsdisplay_cursor *);
148 static void igsfb_update_cursor(struct igsfb_devconfig *, u_int);
149 static void igsfb_convert_cursor_data(struct igsfb_devconfig *,
150 u_int, u_int);
151
152
153 int
154 igsfb_cnattach_subr(dc)
155 struct igsfb_devconfig *dc;
156 {
157 struct rasops_info *ri;
158 long defattr;
159
160 KASSERT(dc == &igsfb_console_dc);
161
162 igsfb_init_video(dc);
163 igsfb_init_wsdisplay(dc);
164
165 dc->dc_nscreens = 1;
166
167 ri = &dc->dc_ri;
168 (*ri->ri_ops.allocattr)(ri,
169 WSCOL_BLACK, /* fg */
170 WSCOL_BLACK, /* bg */
171 0, /* wsattrs */
172 &defattr);
173
174 wsdisplay_cnattach(&igsfb_stdscreen,
175 ri, /* emulcookie */
176 0, 0, /* cursor position */
177 defattr);
178 return (0);
179 }
180
181
182 /*
183 * Finish off the attach. Bus specific attach method should have
184 * enabled io and memory accesses and mapped io (and cop?) registers.
185 */
186 void
187 igsfb_attach_subr(sc, isconsole)
188 struct igsfb_softc *sc;
189 int isconsole;
190 {
191 struct igsfb_devconfig *dc = sc->sc_dc;
192 struct wsemuldisplaydev_attach_args waa;
193
194 KASSERT(dc != NULL);
195
196 if (!isconsole) {
197 igsfb_init_video(dc);
198 igsfb_init_wsdisplay(dc);
199 }
200
201 printf("%s: %dMB, %s%dx%d, %dbpp\n",
202 sc->sc_dev.dv_xname,
203 (u_int32_t)(dc->dc_vmemsz >> 20),
204 (dc->dc_hwflags & IGSFB_HW_BSWAP)
205 ? (dc->dc_hwflags & IGSFB_HW_BE_SELECT)
206 ? "hardware bswap, " : "software bswap, "
207 : "",
208 dc->dc_width, dc->dc_height, dc->dc_depth);
209
210 /* attach wsdisplay */
211 waa.console = isconsole;
212 waa.scrdata = &igsfb_screenlist;
213 waa.accessops = &igsfb_accessops;
214 waa.accesscookie = dc;
215
216 config_found(&sc->sc_dev, &waa, wsemuldisplaydevprint);
217 }
218
219
220 static int
221 igsfb_init_video(dc)
222 struct igsfb_devconfig *dc;
223 {
224 bus_space_handle_t tmph;
225 u_int8_t *p;
226 int need_bswap;
227 bus_addr_t fbaddr, craddr;
228 off_t croffset;
229 u_int8_t busctl, curctl;
230
231 /* Total amount of video memory. */
232 busctl = igs_ext_read(dc->dc_iot, dc->dc_ioh, IGS_EXT_BUS_CTL);
233 if (busctl & 0x2)
234 dc->dc_vmemsz = 4;
235 else if (busctl & 0x1)
236 dc->dc_vmemsz = 2;
237 else
238 dc->dc_vmemsz = 1;
239 dc->dc_vmemsz <<= 20; /* megabytes -> bytes */
240
241 /*
242 * Check for endianness mismatch by writing a word at the end of
243 * the video memory (off-screen) and reading it back byte-by-byte.
244 */
245 if (bus_space_map(dc->dc_memt,
246 dc->dc_memaddr + dc->dc_vmemsz - sizeof(u_int32_t),
247 sizeof(u_int32_t),
248 dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
249 &tmph) != 0)
250 {
251 printf("unable to map video memory for endianness test\n");
252 return (1);
253 }
254
255 p = bus_space_vaddr(dc->dc_memt, tmph);
256 #if BYTE_ORDER == BIG_ENDIAN
257 *((u_int32_t *)p) = 0x12345678;
258 #else
259 *((u_int32_t *)p) = 0x78563412;
260 #endif
261 if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)
262 need_bswap = 0;
263 else
264 need_bswap = 1;
265
266 bus_space_unmap(dc->dc_memt, tmph, sizeof(u_int32_t));
267
268 /*
269 * On CyberPro we can use magic bswap bit in linear address.
270 */
271 fbaddr = dc->dc_memaddr;
272 if (need_bswap) {
273 dc->dc_hwflags |= IGSFB_HW_BSWAP;
274 if (dc->dc_id >= 0x2000) {
275 dc->dc_hwflags |= IGSFB_HW_BE_SELECT;
276 fbaddr |= IGS_MEM_BE_SELECT;
277 }
278 }
279
280 /*
281 * XXX: TODO: make it possible to select the desired video mode.
282 * For now - hardcode to 1024x768/8bpp. This is what Krups OFW uses.
283 */
284 igsfb_hw_setup(dc);
285 delay(10000); /* XXX: uwe */
286
287 dc->dc_width = 1024;
288 dc->dc_height = 768;
289 dc->dc_depth = 8;
290
291 /*
292 * Don't map in all N megs, just the amount we need for the wsscreen.
293 */
294 dc->dc_fbsz = dc->dc_width * dc->dc_height; /* XXX: 8bpp specific */
295 if (bus_space_map(dc->dc_memt, fbaddr, dc->dc_fbsz,
296 dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
297 &dc->dc_fbh) != 0)
298 {
299 bus_space_unmap(dc->dc_iot, dc->dc_ioh, IGS_REG_SIZE);
300 printf("unable to map framebuffer\n");
301 return (1);
302 }
303
304 igsfb_init_cmap(dc);
305
306 /*
307 * 1KB for cursor sprite data at the very end of the video memory.
308 */
309 croffset = dc->dc_vmemsz - IGS_CURSOR_DATA_SIZE;
310 craddr = fbaddr + croffset;
311 if (bus_space_map(dc->dc_memt, craddr, IGS_CURSOR_DATA_SIZE,
312 dc->dc_memflags | BUS_SPACE_MAP_LINEAR,
313 &dc->dc_crh) != 0)
314 {
315 bus_space_unmap(dc->dc_iot, dc->dc_ioh, IGS_REG_SIZE);
316 bus_space_unmap(dc->dc_memt, dc->dc_fbh, dc->dc_fbsz);
317 printf("unable to map cursor sprite region\n");
318 return (1);
319 }
320
321 /*
322 * Tell the device where cursor sprite data are located in the
323 * linear space (it takes data offset in 1KB units).
324 */
325 croffset >>= 10; /* bytes -> kilobytes */
326 igs_ext_write(dc->dc_iot, dc->dc_ioh,
327 IGS_EXT_SPRITE_DATA_LO, croffset & 0xff);
328 igs_ext_write(dc->dc_iot, dc->dc_ioh,
329 IGS_EXT_SPRITE_DATA_HI, (croffset >> 8) & 0xf);
330
331 /* init the bit expansion table for cursor sprite data conversion */
332 igsfb_init_bit_table(dc);
333
334 /* XXX: fill dc_cursor and use igsfb_update_cursor() instead? */
335 memset(&dc->dc_cursor, 0, sizeof(struct igs_hwcursor));
336 memset(bus_space_vaddr(dc->dc_memt, dc->dc_crh),
337 /* transparent */ 0xaa, IGS_CURSOR_DATA_SIZE);
338
339 curctl = igs_ext_read(dc->dc_iot, dc->dc_ioh, IGS_EXT_SPRITE_CTL);
340 curctl |= IGS_EXT_SPRITE_64x64;
341 curctl &= ~IGS_EXT_SPRITE_VISIBLE;
342 igs_ext_write(dc->dc_iot, dc->dc_ioh, IGS_EXT_SPRITE_CTL, curctl);
343 dc->dc_curenb = 0;
344
345 /*
346 * Map abd init graphic coprocessor for accelerated rasops.
347 */
348 if (dc->dc_id >= 0x2000) { /* XXX */
349 if (bus_space_map(dc->dc_iot,
350 dc->dc_iobase + IGS_COP_BASE_B, IGS_COP_SIZE,
351 dc->dc_ioflags,
352 &dc->dc_coph) != 0)
353 {
354 printf("unable to map COP registers\n");
355 return (1);
356 }
357
358 /* XXX: hardcoded 8bpp */
359 bus_space_write_2(dc->dc_iot, dc->dc_coph,
360 IGS_COP_SRC_MAP_WIDTH_REG,
361 dc->dc_width - 1);
362 bus_space_write_2(dc->dc_iot, dc->dc_coph,
363 IGS_COP_DST_MAP_WIDTH_REG,
364 dc->dc_width - 1);
365
366 bus_space_write_1(dc->dc_iot, dc->dc_coph,
367 IGS_COP_MAP_FMT_REG,
368 IGS_COP_MAP_8BPP);
369 }
370
371 /* make sure screen is not blanked */
372 dc->dc_blanked = 0;
373 igsfb_blank_screen(dc, dc->dc_blanked);
374
375 return (0);
376 }
377
378
379 static void
380 igsfb_init_cmap(dc)
381 struct igsfb_devconfig *dc;
382 {
383 bus_space_tag_t iot = dc->dc_iot;
384 bus_space_handle_t ioh = dc->dc_ioh;
385 const u_int8_t *p;
386 int i;
387
388 p = rasops_cmap; /* "ANSI" color map */
389
390 /* init software copy */
391 for (i = 0; i < IGS_CMAP_SIZE; ++i, p += 3) {
392 dc->dc_cmap.r[i] = p[0];
393 dc->dc_cmap.g[i] = p[1];
394 dc->dc_cmap.b[i] = p[2];
395 }
396
397 /* propagate to the device */
398 igsfb_update_cmap(dc, 0, IGS_CMAP_SIZE);
399
400 /* set overscan color (XXX: use defattr's background?) */
401 igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_RED, 0);
402 igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_GREEN, 0);
403 igs_ext_write(iot, ioh, IGS_EXT_OVERSCAN_BLUE, 0);
404 }
405
406
407 static void
408 igsfb_init_wsdisplay(dc)
409 struct igsfb_devconfig *dc;
410 {
411 struct rasops_info *ri;
412 int wsfcookie;
413
414 ri = &dc->dc_ri;
415 ri->ri_hw = dc;
416
417 ri->ri_flg = RI_CENTER | RI_CLEAR;
418 if (IGSFB_HW_SOFT_BSWAP(dc))
419 ri->ri_flg |= RI_BSWAP;
420
421 ri->ri_depth = dc->dc_depth;
422 ri->ri_width = dc->dc_width;
423 ri->ri_height = dc->dc_height;
424
425 ri->ri_stride = dc->dc_width; /* XXX: 8bpp specific */
426 ri->ri_bits = (u_char *)dc->dc_fbh;
427
428 /*
429 * Initialize wsfont related stuff.
430 */
431 wsfont_init();
432
433 /* prefer gallant that is identical to the one the prom uses */
434 wsfcookie = wsfont_find("Gallant", 12, 22, 0,
435 WSDISPLAY_FONTORDER_L2R,
436 WSDISPLAY_FONTORDER_L2R);
437 if (wsfcookie <= 0) {
438 #ifdef DIAGNOSTIC
439 printf("unable to find font Gallant 12x22\n");
440 #endif
441 wsfcookie = wsfont_find(NULL, 0, 0, 0, /* any font at all? */
442 WSDISPLAY_FONTORDER_L2R,
443 WSDISPLAY_FONTORDER_L2R);
444 }
445
446 if (wsfcookie <= 0) {
447 printf("unable to find any fonts\n");
448 return;
449 }
450
451 if (wsfont_lock(wsfcookie, &ri->ri_font) != 0) {
452 printf("unable to lock font\n");
453 return;
454 }
455 ri->ri_wsfcookie = wsfcookie;
456
457
458 /* XXX: TODO: compute term size based on font dimensions? */
459 rasops_init(ri, 34, 80);
460
461
462 /* use the sprite for the text mode cursor */
463 igsfb_make_text_cursor(dc);
464
465 /* the cursor is "busy" while we are in the text mode */
466 dc->dc_hwflags |= IGSFB_HW_TEXT_CURSOR;
467
468 /* propagate sprite data to the device */
469 igsfb_update_cursor(dc, WSDISPLAY_CURSOR_DOSHAPE);
470
471 /* accelerated text cursor */
472 ri->ri_ops.cursor = igsfb_accel_cursor;
473
474 if (dc->dc_id >= 0x2000) { /* XXX */
475 /* accelerated erase/copy */
476 ri->ri_ops.copycols = igsfb_accel_copycols;
477 ri->ri_ops.erasecols = igsfb_accel_erasecols;
478 ri->ri_ops.copyrows = igsfb_accel_copyrows;
479 ri->ri_ops.eraserows = igsfb_accel_eraserows;
480
481 /* putchar hook to sync with the cop */
482 dc->dc_ri_putchar = ri->ri_ops.putchar;
483 ri->ri_ops.putchar = igsfb_accel_putchar;
484 }
485
486 igsfb_stdscreen.nrows = ri->ri_rows;
487 igsfb_stdscreen.ncols = ri->ri_cols;
488 igsfb_stdscreen.textops = &ri->ri_ops;
489 igsfb_stdscreen.capabilities = ri->ri_caps;
490 }
491
492
493 /*
494 * Init cursor data in dc_cursor for the accelerated text cursor.
495 */
496 static int
497 igsfb_make_text_cursor(dc)
498 struct igsfb_devconfig *dc;
499 {
500 struct wsdisplay_font *f = dc->dc_ri.ri_font;
501 u_int16_t cc_scan[8]; /* one sprite scanline */
502 u_int16_t s;
503 int w, i;
504
505 KASSERT(f->fontwidth <= IGS_CURSOR_MAX_SIZE);
506 KASSERT(f->fontheight <= IGS_CURSOR_MAX_SIZE);
507
508 w = f->fontwidth;
509 for (i = 0; i < f->stride; ++i) {
510 if (w >= 8) {
511 s = 0xffff; /* all inverted */
512 w -= 8;
513 } else {
514 /* first w pixels inverted, the rest is transparent */
515 s = ~(0x5555 << (w * 2));
516 if (IGSFB_HW_SOFT_BSWAP(dc))
517 s = bswap16(s);
518 w = 0;
519 }
520 cc_scan[i] = s;
521 }
522
523 dc->dc_cursor.cc_size.x = f->fontwidth;
524 dc->dc_cursor.cc_size.y = f->fontheight;
525
526 dc->dc_cursor.cc_hot.x = 0;
527 dc->dc_cursor.cc_hot.y = 0;
528
529 /* init sprite array to be all transparent */
530 memset(dc->dc_cursor.cc_sprite, 0xaa, IGS_CURSOR_DATA_SIZE);
531
532 for (i = 0; i < f->fontheight; ++i)
533 memcpy(&dc->dc_cursor.cc_sprite[i * 8],
534 cc_scan, f->stride * sizeof(u_int16_t));
535
536 return (0);
537 }
538
539
540 /*
541 * Spread a byte (abcd.efgh) into two (0a0b.0c0d 0e0f.0g0h).
542 * Helper function for igsfb_init_bit_table().
543 */
544 static u_int16_t
545 igsfb_spread_bits_8(b)
546 u_int8_t b;
547 {
548 u_int16_t s = b;
549
550 s = ((s & 0x00f0) << 4) | (s & 0x000f);
551 s = ((s & 0x0c0c) << 2) | (s & 0x0303);
552 s = ((s & 0x2222) << 1) | (s & 0x1111);
553 return (s);
554 }
555
556
557 /*
558 * Cursor sprite data are in 2bpp. Incoming image/mask are in 1bpp.
559 * Prebuild the table to expand 1bpp->2bpp, with bswapping if neccessary.
560 */
561 static void
562 igsfb_init_bit_table(dc)
563 struct igsfb_devconfig *dc;
564 {
565 u_int16_t *expand = dc->dc_bexpand;
566 int need_bswap = IGSFB_HW_SOFT_BSWAP(dc);
567 u_int16_t s;
568 u_int i;
569
570 for (i = 0; i < 256; ++i) {
571 s = igsfb_spread_bits_8(i);
572 expand[i] = need_bswap ? bswap16(s) : s;
573 }
574 }
575
576
577 /*
578 * wsdisplay_accessops: mmap()
579 * XXX: allow mmapping i/o mapped i/o regs if INSECURE???
580 */
581 static paddr_t
582 igsfb_mmap(v, offset, prot)
583 void *v;
584 off_t offset;
585 int prot;
586 {
587 struct igsfb_devconfig *dc = v;
588
589 if (offset >= dc->dc_memsz || offset < 0)
590 return (-1);
591
592 return (bus_space_mmap(dc->dc_memt, dc->dc_memaddr, offset, prot,
593 dc->dc_memflags | BUS_SPACE_MAP_LINEAR));
594 }
595
596
597 /*
598 * wsdisplay_accessops: ioctl()
599 */
600 static int
601 igsfb_ioctl(v, cmd, data, flag, p)
602 void *v;
603 u_long cmd;
604 caddr_t data;
605 int flag;
606 struct proc *p;
607 {
608 struct igsfb_devconfig *dc = v;
609 struct rasops_info *ri;
610 int cursor_busy;
611 int turnoff;
612
613 /* don't permit cursor ioctls if we use sprite for text cursor */
614 cursor_busy = !dc->dc_mapped
615 && (dc->dc_hwflags & IGSFB_HW_TEXT_CURSOR);
616
617 switch (cmd) {
618
619 case WSDISPLAYIO_GTYPE:
620 *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
621 return (0);
622
623 case WSDISPLAYIO_GINFO:
624 ri = &dc->dc_ri;
625 #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
626 wsd_fbip->height = ri->ri_height;
627 wsd_fbip->width = ri->ri_width;
628 wsd_fbip->depth = ri->ri_depth;
629 wsd_fbip->cmsize = IGS_CMAP_SIZE;
630 #undef wsd_fbip
631 return (0);
632
633 case WSDISPLAYIO_SMODE:
634 #define d (*(int *)data)
635 if (d == WSDISPLAYIO_MODE_MAPPED)
636 dc->dc_mapped = 1;
637 else {
638 dc->dc_mapped = 0;
639 /* reinit sprite for text cursor */
640 if (dc->dc_hwflags & IGSFB_HW_TEXT_CURSOR) {
641 igsfb_make_text_cursor(dc);
642 dc->dc_curenb = 0;
643 igsfb_update_cursor(dc,
644 WSDISPLAY_CURSOR_DOSHAPE
645 | WSDISPLAY_CURSOR_DOCUR);
646 }
647 }
648 return (0);
649
650 case WSDISPLAYIO_GVIDEO:
651 *(u_int *)data = dc->dc_blanked ?
652 WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
653 return (0);
654
655 case WSDISPLAYIO_SVIDEO:
656 turnoff = (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF);
657 if (dc->dc_blanked != turnoff) {
658 dc->dc_blanked = turnoff;
659 igsfb_blank_screen(dc, dc->dc_blanked);
660 }
661 return (0);
662
663 case WSDISPLAYIO_GETCMAP:
664 return (igsfb_get_cmap(dc, (struct wsdisplay_cmap *)data));
665
666 case WSDISPLAYIO_PUTCMAP:
667 return (igsfb_set_cmap(dc, (struct wsdisplay_cmap *)data));
668
669 case WSDISPLAYIO_GCURMAX:
670 ((struct wsdisplay_curpos *)data)->x = IGS_CURSOR_MAX_SIZE;
671 ((struct wsdisplay_curpos *)data)->y = IGS_CURSOR_MAX_SIZE;
672 return (0);
673
674 case WSDISPLAYIO_GCURPOS:
675 if (cursor_busy)
676 return (EBUSY);
677 *(struct wsdisplay_curpos *)data = dc->dc_cursor.cc_pos;
678 return (0);
679
680 case WSDISPLAYIO_SCURPOS:
681 if (cursor_busy)
682 return (EBUSY);
683 igsfb_set_curpos(dc, (struct wsdisplay_curpos *)data);
684 return (0);
685
686 case WSDISPLAYIO_GCURSOR:
687 if (cursor_busy)
688 return (EBUSY);
689 return (igsfb_get_cursor(dc, (struct wsdisplay_cursor *)data));
690
691 case WSDISPLAYIO_SCURSOR:
692 if (cursor_busy)
693 return (EBUSY);
694 return (igsfb_set_cursor(dc, (struct wsdisplay_cursor *)data));
695 }
696
697 return (EPASSTHROUGH);
698 }
699
700
701 /*
702 * wsdisplay_accessops: ioctl(WSDISPLAYIO_SVIDEO)
703 */
704 static void
705 igsfb_blank_screen(dc, blank)
706 struct igsfb_devconfig *dc;
707 int blank;
708 {
709
710 igs_ext_write(dc->dc_iot, dc->dc_ioh,
711 IGS_EXT_SYNC_CTL,
712 blank ? IGS_EXT_SYNC_H0 | IGS_EXT_SYNC_V0
713 : 0);
714 }
715
716
717 /*
718 * wsdisplay_accessops: ioctl(WSDISPLAYIO_GETCMAP)
719 * Served from the software cmap copy.
720 */
721 static int
722 igsfb_get_cmap(dc, p)
723 struct igsfb_devconfig *dc;
724 struct wsdisplay_cmap *p;
725 {
726 u_int index, count;
727 int err;
728
729 index = p->index;
730 count = p->count;
731
732 if (index >= IGS_CMAP_SIZE || count > IGS_CMAP_SIZE - index)
733 return (EINVAL);
734
735 err = copyout(&dc->dc_cmap.r[index], p->red, count);
736 if (err)
737 return (err);
738 err = copyout(&dc->dc_cmap.g[index], p->green, count);
739 if (err)
740 return (err);
741 err = copyout(&dc->dc_cmap.b[index], p->blue, count);
742 if (err)
743 return (err);
744
745 return (0);
746 }
747
748
749 /*
750 * wsdisplay_accessops: ioctl(WSDISPLAYIO_SETCMAP)
751 * Set the software cmap copy and propagate changed range to the device.
752 */
753 static int
754 igsfb_set_cmap(dc, p)
755 struct igsfb_devconfig *dc;
756 const struct wsdisplay_cmap *p;
757 {
758 u_int index, count;
759
760 index = p->index;
761 count = p->count;
762
763 if (index >= IGS_CMAP_SIZE || count > IGS_CMAP_SIZE - index)
764 return (EINVAL);
765
766 if (!uvm_useracc(p->red, count, B_READ) ||
767 !uvm_useracc(p->green, count, B_READ) ||
768 !uvm_useracc(p->blue, count, B_READ))
769 return (EFAULT);
770
771 copyin(p->red, &dc->dc_cmap.r[index], count);
772 copyin(p->green, &dc->dc_cmap.g[index], count);
773 copyin(p->blue, &dc->dc_cmap.b[index], count);
774
775 /* propagate changes to the device */
776 igsfb_update_cmap(dc, index, count);
777
778 return (0);
779 }
780
781
782 /*
783 * Propagate specified part of the software cmap copy to the device.
784 */
785 static void
786 igsfb_update_cmap(dc, index, count)
787 struct igsfb_devconfig *dc;
788 u_int index, count;
789 {
790 bus_space_tag_t t;
791 bus_space_handle_t h;
792 u_int last, i;
793
794 if (index >= IGS_CMAP_SIZE)
795 return;
796
797 last = index + count;
798 if (last > IGS_CMAP_SIZE)
799 last = IGS_CMAP_SIZE;
800
801 t = dc->dc_iot;
802 h = dc->dc_ioh;
803
804 /* start palette writing, index is autoincremented by hardware */
805 bus_space_write_1(t, h, IGS_DAC_PEL_WRITE_IDX, index);
806
807 for (i = index; i < last; ++i) {
808 bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.r[i]);
809 bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.g[i]);
810 bus_space_write_1(t, h, IGS_DAC_PEL_DATA, dc->dc_cmap.b[i]);
811 }
812 }
813
814
815 /*
816 * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURPOS)
817 */
818 static void
819 igsfb_set_curpos(dc, curpos)
820 struct igsfb_devconfig *dc;
821 const struct wsdisplay_curpos *curpos;
822 {
823 struct rasops_info *ri = &dc->dc_ri;
824 u_int x = curpos->x, y = curpos->y;
825
826 if (x >= ri->ri_width)
827 x = ri->ri_width - 1;
828 if (y >= ri->ri_height)
829 y = ri->ri_height - 1;
830
831 dc->dc_cursor.cc_pos.x = x;
832 dc->dc_cursor.cc_pos.y = y;
833
834 /* propagate changes to the device */
835 igsfb_update_curpos(dc);
836 }
837
838
839 static void
840 igsfb_update_curpos(dc)
841 struct igsfb_devconfig *dc;
842 {
843 bus_space_tag_t t;
844 bus_space_handle_t h;
845 int x, xoff, y, yoff;
846
847 xoff = 0;
848 x = dc->dc_cursor.cc_pos.x - dc->dc_cursor.cc_hot.x;
849 if (x < 0) {
850 xoff = -x;
851 x = 0;
852 }
853
854 yoff = 0;
855 y = dc->dc_cursor.cc_pos.y - dc->dc_cursor.cc_hot.y;
856 if (y < 0) {
857 yoff = -y;
858 y = 0;
859 }
860
861 t = dc->dc_iot;
862 h = dc->dc_ioh;
863
864 igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_LO, x & 0xff);
865 igs_ext_write(t, h, IGS_EXT_SPRITE_HSTART_HI, (x >> 8) & 0x07);
866 igs_ext_write(t, h, IGS_EXT_SPRITE_HPRESET, xoff & 0x3f);
867
868 igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_LO, y & 0xff);
869 igs_ext_write(t, h, IGS_EXT_SPRITE_VSTART_HI, (y >> 8) & 0x07);
870 igs_ext_write(t, h, IGS_EXT_SPRITE_VPRESET, yoff & 0x3f);
871 }
872
873
874 /*
875 * wsdisplay_accessops: ioctl(WSDISPLAYIO_GCURSOR)
876 */
877 static int
878 igsfb_get_cursor(dc, p)
879 struct igsfb_devconfig *dc;
880 struct wsdisplay_cursor *p;
881 {
882
883 /* XXX: TODO */
884 return (0);
885 }
886
887
888 /*
889 * wsdisplay_accessops: ioctl(WSDISPLAYIO_SCURSOR)
890 */
891 static int
892 igsfb_set_cursor(dc, p)
893 struct igsfb_devconfig *dc;
894 const struct wsdisplay_cursor *p;
895 {
896 struct igs_hwcursor *cc;
897 struct wsdisplay_curpos pos, hot;
898 u_int v, index, count, icount, iwidth;
899
900 cc = &dc->dc_cursor;
901 v = p->which;
902
903 /* verify that the new cursor colormap is valid */
904 if (v & WSDISPLAY_CURSOR_DOCMAP) {
905 index = p->cmap.index;
906 count = p->cmap.count;
907 if (index >= 2 || (index + count) > 2)
908 return (EINVAL);
909
910 if (!uvm_useracc(p->cmap.red, count, B_READ)
911 || !uvm_useracc(p->cmap.green, count, B_READ)
912 || !uvm_useracc(p->cmap.blue, count, B_READ))
913 return (EFAULT);
914 }
915
916 /* verify that the new cursor data are valid */
917 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
918 if (p->size.x > IGS_CURSOR_MAX_SIZE
919 || p->size.y > IGS_CURSOR_MAX_SIZE)
920 return (EINVAL);
921
922 iwidth = (p->size.x + 7) >> 3; /* bytes per scan line */
923 icount = iwidth * p->size.y;
924 if (!uvm_useracc(p->image, icount, B_READ)
925 || !uvm_useracc(p->mask, icount, B_READ))
926 return (EFAULT);
927 }
928
929 /* enforce that the position is within screen bounds */
930 if (v & WSDISPLAY_CURSOR_DOPOS) {
931 struct rasops_info *ri = &dc->dc_ri;
932
933 pos = p->pos; /* local copy we can write to */
934 if (pos.x >= ri->ri_width)
935 pos.x = ri->ri_width - 1;
936 if (pos.y >= ri->ri_height)
937 pos.y = ri->ri_height - 1;
938 }
939
940 /* enforce that the hot spot is within sprite bounds */
941 if (v & WSDISPLAY_CURSOR_DOHOT)
942 hot = p->hot; /* local copy we can write to */
943
944 if (v & (WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOSHAPE)) {
945 const struct wsdisplay_curpos *nsize;
946 struct wsdisplay_curpos *nhot;
947
948 nsize = (v & WSDISPLAY_CURSOR_DOSHAPE) ?
949 &p->size : &cc->cc_size;
950 nhot = (v & WSDISPLAY_CURSOR_DOHOT) ? &hot : &cc->cc_hot;
951
952 if (nhot->x >= nsize->x)
953 nhot->x = nsize->x - 1;
954 if (nhot->y >= nsize->y)
955 nhot->y = nsize->y - 1;
956 }
957
958
959 /* arguments verified, copy data to the driver's cursor info */
960 if (v & WSDISPLAY_CURSOR_DOCUR)
961 dc->dc_curenb = p->enable;
962
963 if (v & WSDISPLAY_CURSOR_DOPOS)
964 cc->cc_pos = pos; /* local copy, possibly corrected */
965
966 if (v & WSDISPLAY_CURSOR_DOHOT)
967 cc->cc_hot = hot; /* local copy, possibly corrected */
968
969 if (v & WSDISPLAY_CURSOR_DOCMAP) {
970 copyin(p->cmap.red, &cc->cc_color[index], count);
971 copyin(p->cmap.green, &cc->cc_color[index + 2], count);
972 copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
973 }
974
975 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
976 u_int trailing_bits;
977
978 copyin(p->image, cc->cc_image, icount);
979 copyin(p->mask, cc->cc_mask, icount);
980 cc->cc_size = p->size;
981
982 /* clear trailing bits in the "partial" mask bytes */
983 trailing_bits = p->size.x & 0x07;
984 if (trailing_bits != 0) {
985 const u_int cutmask = ~((~0) << trailing_bits);
986 u_char *mp;
987 u_int i;
988
989 mp = cc->cc_mask + iwidth - 1;
990 for (i = 0; i < p->size.y; ++i) {
991 *mp &= cutmask;
992 mp += iwidth;
993 }
994 }
995 igsfb_convert_cursor_data(dc, iwidth, p->size.y);
996 }
997
998 /* propagate changes to the device */
999 igsfb_update_cursor(dc, v);
1000
1001 return (0);
1002 }
1003
1004
1005 /*
1006 * Convert incoming 1bpp cursor image/mask into native 2bpp format.
1007 */
1008 static void
1009 igsfb_convert_cursor_data(dc, width, height)
1010 struct igsfb_devconfig *dc;
1011 u_int width, height;
1012 {
1013 struct igs_hwcursor *cc = &dc->dc_cursor;
1014 u_int16_t *expand = dc->dc_bexpand;
1015 u_int8_t *ip, *mp;
1016 u_int16_t is, ms, *dp;
1017 u_int line, i;
1018
1019 /* init sprite to be all transparent */
1020 memset(cc->cc_sprite, 0xaa, IGS_CURSOR_DATA_SIZE);
1021
1022 /* first scanline */
1023 ip = cc->cc_image;
1024 mp = cc->cc_mask;
1025 dp = cc->cc_sprite;
1026
1027 for (line = 0; line < height; ++line) {
1028 for (i = 0; i < width; ++i) {
1029 is = expand[ip[i]]; /* image: 0 -> 00, 1 -> 01 */
1030 ms = expand[mp[i]]; /* mask: 0 -> 00, 1 -> 11 */
1031 ms |= (ms << 1);
1032 dp[i] = (0xaaaa & ~ms) | (is & ms);
1033 }
1034
1035 /* next scanline */
1036 ip += width;
1037 mp += width;
1038 dp += 8; /* 64 pixels, 2bpp, 8 pixels per short = 8 shorts */
1039 }
1040 }
1041
1042
1043 /*
1044 * Propagate cursor changes to the device.
1045 * "which" is composed of WSDISPLAY_CURSOR_DO* bits.
1046 */
1047 static void
1048 igsfb_update_cursor(dc, which)
1049 struct igsfb_devconfig *dc;
1050 u_int which;
1051 {
1052 bus_space_tag_t iot = dc->dc_iot;
1053 bus_space_handle_t ioh = dc->dc_ioh;
1054 u_int8_t curctl;
1055
1056 /*
1057 * We will need to tweak sprite control register for cursor
1058 * visibility and cursor color map manipualtion.
1059 */
1060 if (which & (WSDISPLAY_CURSOR_DOCUR | WSDISPLAY_CURSOR_DOCMAP)) {
1061 curctl = igs_ext_read(iot, ioh, IGS_EXT_SPRITE_CTL);
1062 }
1063
1064 if (which & WSDISPLAY_CURSOR_DOSHAPE) {
1065 u_int8_t *dst = bus_space_vaddr(dc->dc_memt, dc->dc_crh);
1066
1067 /*
1068 * memcpy between spaces of different endianness would
1069 * be ... special. We cannot be sure if memcpy gonna
1070 * push data in 4-byte chunks, we can't pre-bswap it,
1071 * so do it byte-by-byte to preserve byte ordering.
1072 */
1073 if (IGSFB_HW_SOFT_BSWAP(dc)) {
1074 u_int8_t *src = (u_int8_t *)dc->dc_cursor.cc_sprite;
1075 int i;
1076
1077 for (i = 0; i < IGS_CURSOR_DATA_SIZE; ++i)
1078 *dst++ = *src++;
1079 } else {
1080 memcpy(dst, dc->dc_cursor.cc_sprite,
1081 IGS_CURSOR_DATA_SIZE);
1082 }
1083 }
1084
1085 if (which & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
1086 /* code shared with WSDISPLAYIO_SCURPOS */
1087 igsfb_update_curpos(dc);
1088 }
1089
1090 if (which & WSDISPLAY_CURSOR_DOCMAP) {
1091 u_int8_t *p;
1092
1093 /* tell DAC we want access to the cursor palette */
1094 igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
1095 curctl | IGS_EXT_SPRITE_DAC_PEL);
1096
1097 p = dc->dc_cursor.cc_color;
1098
1099 bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 0);
1100 bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[0]);
1101 bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[2]);
1102 bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[4]);
1103
1104 bus_space_write_1(iot, ioh, IGS_DAC_PEL_WRITE_IDX, 1);
1105 bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[1]);
1106 bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[3]);
1107 bus_space_write_1(iot, ioh, IGS_DAC_PEL_DATA, p[5]);
1108
1109 /* restore access to the normal palette */
1110 igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL, curctl);
1111 }
1112
1113 if (which & WSDISPLAY_CURSOR_DOCUR) {
1114 if ((curctl & IGS_EXT_SPRITE_VISIBLE) == 0
1115 && dc->dc_curenb)
1116 igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
1117 curctl | IGS_EXT_SPRITE_VISIBLE);
1118 else if ((curctl & IGS_EXT_SPRITE_VISIBLE) != 0
1119 && !dc->dc_curenb)
1120 igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
1121 curctl & ~IGS_EXT_SPRITE_VISIBLE);
1122 }
1123 }
1124
1125
1126 /*
1127 * wsdisplay_accessops: alloc_screen()
1128 */
1129 static int
1130 igsfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
1131 void *v;
1132 const struct wsscreen_descr *type;
1133 void **cookiep;
1134 int *curxp, *curyp;
1135 long *attrp;
1136 {
1137 struct igsfb_devconfig *dc = v;
1138 struct rasops_info *ri = &dc->dc_ri;
1139
1140 if (dc->dc_nscreens > 0) /* only do single screen for now */
1141 return (ENOMEM);
1142
1143 dc->dc_nscreens = 1;
1144
1145 *cookiep = ri; /* emulcookie for igsgfb_stdscreen.textops */
1146 *curxp = *curyp = 0; /* cursor position */
1147 (*ri->ri_ops.allocattr)(ri,
1148 WSCOL_BLACK, /* fg */
1149 WSCOL_BLACK, /* bg */
1150 0, /* wsattr */
1151 attrp);
1152 return (0);
1153 }
1154
1155
1156 /*
1157 * wsdisplay_accessops: free_screen()
1158 */
1159 static void
1160 igsfb_free_screen(v, cookie)
1161 void *v;
1162 void *cookie;
1163 {
1164
1165 /* XXX */
1166 return;
1167 }
1168
1169
1170 /*
1171 * wsdisplay_accessops: show_screen()
1172 */
1173 static int
1174 igsfb_show_screen(v, cookie, waitok, cb, cbarg)
1175 void *v;
1176 void *cookie;
1177 int waitok;
1178 void (*cb)(void *, int, int);
1179 void *cbarg;
1180 {
1181
1182 /* XXX */
1183 return (0);
1184 }
1185
1186
1187
1188 /*
1189 * Accelerated text mode cursor that uses hardware sprite.
1190 */
1191 static void
1192 igsfb_accel_cursor(cookie, on, row, col)
1193 void *cookie;
1194 int on, row, col;
1195 {
1196 struct rasops_info *ri = (struct rasops_info *)cookie;
1197 struct igsfb_devconfig *dc = (struct igsfb_devconfig *)ri->ri_hw;
1198 struct igs_hwcursor *cc = &dc->dc_cursor;
1199 u_int which;
1200
1201 ri->ri_crow = row;
1202 ri->ri_ccol = col;
1203
1204 which = 0;
1205 if (on) {
1206 ri->ri_flg |= RI_CURSOR;
1207
1208 /* only bother to move the cursor if it's visibile */
1209 cc->cc_pos.x = ri->ri_xorigin
1210 + ri->ri_ccol * ri->ri_font->fontwidth;
1211 cc->cc_pos.y = ri->ri_yorigin
1212 + ri->ri_crow * ri->ri_font->fontheight;
1213 which |= WSDISPLAY_CURSOR_DOPOS;
1214 } else
1215 ri->ri_flg &= ~RI_CURSOR;
1216
1217 if (dc->dc_curenb != on) {
1218 dc->dc_curenb = on;
1219 which |= WSDISPLAY_CURSOR_DOCUR;
1220 }
1221
1222 /* propagate changes to the device */
1223 igsfb_update_cursor(dc, which);
1224 }
1225
1226
1227
1228 /*
1229 * Accelerated raster ops that use graphic coprocessor.
1230 */
1231
1232 static int
1233 igsfb_accel_wait(dc)
1234 struct igsfb_devconfig *dc;
1235 {
1236 bus_space_tag_t t = dc->dc_iot;
1237 bus_space_handle_t h = dc->dc_coph;
1238 int timo = 100000;
1239 u_int8_t reg;
1240
1241 while (timo--) {
1242 reg = bus_space_read_1(t, h, IGS_COP_CTL_REG);
1243 if ((reg & IGS_COP_CTL_BUSY) == 0)
1244 return (0);
1245 }
1246
1247 return (1);
1248 }
1249
1250
1251 static void
1252 igsfb_accel_copy(dc, src, dst, width, height)
1253 struct igsfb_devconfig *dc;
1254 u_int32_t src, dst;
1255 u_int16_t width, height;
1256 {
1257 bus_space_tag_t t = dc->dc_iot;
1258 bus_space_handle_t h = dc->dc_coph;
1259 u_int32_t toend;
1260 u_int8_t drawcmd;
1261
1262 drawcmd = IGS_COP_DRAW_ALL;
1263 if (dst > src) {
1264 toend = dc->dc_ri.ri_width * (height - 1) + (width - 1);
1265 src += toend;
1266 dst += toend;
1267 drawcmd |= IGS_COP_OCTANT_X_NEG | IGS_COP_OCTANT_Y_NEG;
1268 }
1269
1270 igsfb_accel_wait(dc);
1271 bus_space_write_1(t, h, IGS_COP_CTL_REG, 0);
1272
1273 bus_space_write_1(t, h, IGS_COP_FG_MIX_REG, IGS_COP_MIX_S);
1274
1275 bus_space_write_2(t, h, IGS_COP_WIDTH_REG, width - 1);
1276 bus_space_write_2(t, h, IGS_COP_HEIGHT_REG, height - 1);
1277
1278 bus_space_write_4(t, h, IGS_COP_SRC_START_REG, src);
1279 bus_space_write_4(t, h, IGS_COP_DST_START_REG, dst);
1280
1281 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_0_REG, drawcmd);
1282 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_1_REG, IGS_COP_PPM_FIXED_FG);
1283 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_2_REG, 0);
1284 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_3_REG,
1285 IGS_COP_OP_PXBLT | IGS_COP_OP_FG_FROM_SRC);
1286 }
1287
1288 static void
1289 igsfb_accel_fill(dc, color, dst, width, height)
1290 struct igsfb_devconfig *dc;
1291 u_int32_t color;
1292 u_int32_t dst;
1293 u_int16_t width, height;
1294 {
1295 bus_space_tag_t t = dc->dc_iot;
1296 bus_space_handle_t h = dc->dc_coph;
1297
1298 igsfb_accel_wait(dc);
1299 bus_space_write_1(t, h, IGS_COP_CTL_REG, 0);
1300
1301 bus_space_write_1(t, h, IGS_COP_FG_MIX_REG, IGS_COP_MIX_S);
1302
1303 bus_space_write_2(t, h, IGS_COP_WIDTH_REG, width - 1);
1304 bus_space_write_2(t, h, IGS_COP_HEIGHT_REG, height - 1);
1305
1306 bus_space_write_4(t, h, IGS_COP_DST_START_REG, dst);
1307 bus_space_write_4(t, h, IGS_COP_FG_REG, color);
1308
1309 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_0_REG, IGS_COP_DRAW_ALL);
1310 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_1_REG, IGS_COP_PPM_FIXED_FG);
1311 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_2_REG, 0);
1312 bus_space_write_1(t, h, IGS_COP_PIXEL_OP_3_REG, IGS_COP_OP_PXBLT);
1313 }
1314
1315
1316 static void
1317 igsfb_accel_copyrows(cookie, src, dst, num)
1318 void *cookie;
1319 int src, dst, num;
1320 {
1321 struct rasops_info *ri = (struct rasops_info *)cookie;
1322 struct igsfb_devconfig *dc = (struct igsfb_devconfig *)ri->ri_hw;
1323 u_int32_t srp, dsp;
1324 u_int16_t width, height;
1325
1326 width = ri->ri_emuwidth;
1327 height = num * ri->ri_font->fontheight;
1328
1329 srp = ri->ri_xorigin
1330 + ri->ri_width * (ri->ri_yorigin
1331 + src * ri->ri_font->fontheight);
1332 dsp = ri->ri_xorigin
1333 + ri->ri_width * (ri->ri_yorigin
1334 + dst * ri->ri_font->fontheight);
1335
1336 igsfb_accel_copy(dc, srp, dsp, width, height);
1337 }
1338
1339
1340 void
1341 igsfb_accel_copycols(cookie, row, src, dst, num)
1342 void *cookie;
1343 int row, src, dst, num;
1344 {
1345 struct rasops_info *ri = (struct rasops_info *)cookie;
1346 struct igsfb_devconfig *dc = (struct igsfb_devconfig *)ri->ri_hw;
1347 u_int32_t rowp, srp, dsp;
1348 u_int16_t width, height;
1349
1350 width = num * ri->ri_font->fontwidth;
1351 height = ri->ri_font->fontheight;
1352
1353 rowp = ri->ri_xorigin
1354 + ri->ri_width * (ri->ri_yorigin
1355 + row * ri->ri_font->fontheight);
1356
1357 srp = rowp + src * ri->ri_font->fontwidth;
1358 dsp = rowp + dst * ri->ri_font->fontwidth;
1359
1360 igsfb_accel_copy(dc, srp, dsp, width, height);
1361 }
1362
1363
1364 static void
1365 igsfb_accel_eraserows(cookie, row, num, attr)
1366 void *cookie;
1367 int row, num;
1368 long attr;
1369 {
1370 struct rasops_info *ri = (struct rasops_info *)cookie;
1371 struct igsfb_devconfig *dc = (struct igsfb_devconfig *)ri->ri_hw;
1372 u_int32_t color;
1373 u_int32_t dsp;
1374 u_int16_t width, height;
1375
1376 width = ri->ri_emuwidth;
1377 height = num * ri->ri_font->fontheight;
1378
1379 dsp = ri->ri_xorigin
1380 + ri->ri_width * (ri->ri_yorigin
1381 + row * ri->ri_font->fontheight);
1382
1383 /* XXX: we "know" the encoding that rasops' allocattr uses */
1384 color = (attr >> 16) & 0xff;
1385
1386 igsfb_accel_fill(dc, color, dsp, width, height);
1387 }
1388
1389
1390 void
1391 igsfb_accel_erasecols(cookie, row, col, num, attr)
1392 void *cookie;
1393 int row, col, num;
1394 long attr;
1395 {
1396 struct rasops_info *ri = (struct rasops_info *)cookie;
1397 struct igsfb_devconfig *dc = (struct igsfb_devconfig *)ri->ri_hw;
1398 u_int32_t color;
1399 u_int32_t rowp, dsp;
1400 u_int16_t width, height;
1401
1402 width = num * ri->ri_font->fontwidth;
1403 height = ri->ri_font->fontheight;
1404
1405 rowp = ri->ri_xorigin
1406 + ri->ri_width * (ri->ri_yorigin
1407 + row * ri->ri_font->fontheight);
1408
1409 dsp = rowp + col * ri->ri_font->fontwidth;
1410
1411 /* XXX: we "know" the encoding that rasops' allocattr uses */
1412 color = (attr >> 16) & 0xff;
1413
1414 igsfb_accel_fill(dc, color, dsp, width, height);
1415 }
1416
1417
1418 /*
1419 * Not really implemented here, but we need to hook into the one
1420 * supplied by rasops so that we can synchronize with the COP.
1421 */
1422 static void
1423 igsfb_accel_putchar(cookie, row, col, uc, attr)
1424 void *cookie;
1425 int row, col;
1426 u_int uc;
1427 long attr;
1428 {
1429 struct rasops_info *ri = (struct rasops_info *)cookie;
1430 struct igsfb_devconfig *dc = (struct igsfb_devconfig *)ri->ri_hw;
1431
1432 igsfb_accel_wait(dc);
1433 (*dc->dc_ri_putchar)(cookie, row, col, uc, attr);
1434 }
1435