1 /*
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
8 *
9 * All advertising materials mentioning features or use of this software
10 * must display the following acknowledgement:
11 * This product includes software developed by the University of
12 * California, Lawrence Berkeley Laboratory.
13 *
14 * %sccs.include.redist.c%
15 *
16 * @(#)bt_subr.c 8.2 (Berkeley) 01/21/94
17 *
18 * from: $Header: bt_subr.c,v 1.1 93/10/12 15:28:39 torek Exp $
19 */
20
21 #include <sys/param.h>
22 #include <sys/buf.h>
23 #include <sys/errno.h>
24 #include <sys/fbio.h>
25
26 #include <sparc/sbus/btreg.h>
27 #include <sparc/sbus/btvar.h>
28
29 /*
30 * Common code for dealing with Brooktree video DACs.
31 * (Contains some software-only code as well, since the colormap
32 * ioctls are shared between the cgthree and cgsix drivers.)
33 */
34
35 /*
36 * Implement an FBIOGETCMAP-like ioctl.
37 */
38 int
bt_getcmap(p,cm,cmsize)39 bt_getcmap(p, cm, cmsize)
40 register struct fbcmap *p;
41 union bt_cmap *cm;
42 int cmsize;
43 {
44 register u_int i, start, count;
45 register u_char *cp;
46
47 start = p->index;
48 count = p->count;
49 if (start >= cmsize || start + count > cmsize)
50 return (EINVAL);
51 if (!useracc(p->red, count, B_WRITE) ||
52 !useracc(p->green, count, B_WRITE) ||
53 !useracc(p->blue, count, B_WRITE))
54 return (EFAULT);
55 for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 3, i++) {
56 p->red[i] = cp[0];
57 p->green[i] = cp[1];
58 p->blue[i] = cp[2];
59 }
60 return (0);
61 }
62
63 /*
64 * Implement the software portion of an FBIOPUTCMAP-like ioctl.
65 */
66 int
bt_putcmap(p,cm,cmsize)67 bt_putcmap(p, cm, cmsize)
68 register struct fbcmap *p;
69 union bt_cmap *cm;
70 int cmsize;
71 {
72 register u_int i, start, count;
73 register u_char *cp;
74
75 start = p->index;
76 count = p->count;
77 if (start >= cmsize || start + count > cmsize)
78 return (EINVAL);
79 if (!useracc(p->red, count, B_READ) ||
80 !useracc(p->green, count, B_READ) ||
81 !useracc(p->blue, count, B_READ))
82 return (EFAULT);
83 for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 3, i++) {
84 cp[0] = p->red[i];
85 cp[1] = p->green[i];
86 cp[2] = p->blue[i];
87 }
88 return (0);
89 }
90