xref: /csrg-svn/sys/sparc/sbus/bt_subr.c (revision 65800)
164774Storek /*
2*65800Sbostic  * Copyright (c) 1993
3*65800Sbostic  *	The Regents of the University of California.  All rights reserved.
464774Storek  *
564774Storek  * This software was developed by the Computer Systems Engineering group
664774Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
764774Storek  * contributed to Berkeley.
864774Storek  *
964774Storek  * All advertising materials mentioning features or use of this software
1064774Storek  * must display the following acknowledgement:
1164774Storek  *	This product includes software developed by the University of
1264774Storek  *	California, Lawrence Berkeley Laboratory.
1364774Storek  *
1464774Storek  * %sccs.include.redist.c%
1564774Storek  *
16*65800Sbostic  *	@(#)bt_subr.c	8.2 (Berkeley) 01/21/94
1764774Storek  *
1864774Storek  * from: $Header: bt_subr.c,v 1.1 93/10/12 15:28:39 torek Exp $
1964774Storek  */
2064774Storek 
2164774Storek #include <sys/param.h>
2264774Storek #include <sys/buf.h>
2364774Storek #include <sys/errno.h>
2464774Storek #include <sys/fbio.h>
2564774Storek 
2664774Storek #include <sparc/sbus/btreg.h>
2764774Storek #include <sparc/sbus/btvar.h>
2864774Storek 
2964774Storek /*
3064774Storek  * Common code for dealing with Brooktree video DACs.
3164774Storek  * (Contains some software-only code as well, since the colormap
3264774Storek  * ioctls are shared between the cgthree and cgsix drivers.)
3364774Storek  */
3464774Storek 
3564774Storek /*
3664774Storek  * Implement an FBIOGETCMAP-like ioctl.
3764774Storek  */
3864774Storek int
bt_getcmap(p,cm,cmsize)3964774Storek bt_getcmap(p, cm, cmsize)
4064774Storek 	register struct fbcmap *p;
4164774Storek 	union bt_cmap *cm;
4264774Storek 	int cmsize;
4364774Storek {
4464774Storek 	register u_int i, start, count;
4564774Storek 	register u_char *cp;
4664774Storek 
4764774Storek 	start = p->index;
4864774Storek 	count = p->count;
4964774Storek 	if (start >= cmsize || start + count > cmsize)
5064774Storek 		return (EINVAL);
5164774Storek 	if (!useracc(p->red, count, B_WRITE) ||
5264774Storek 	    !useracc(p->green, count, B_WRITE) ||
5364774Storek 	    !useracc(p->blue, count, B_WRITE))
5464774Storek 		return (EFAULT);
5564774Storek 	for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 3, i++) {
5664774Storek 		p->red[i] = cp[0];
5764774Storek 		p->green[i] = cp[1];
5864774Storek 		p->blue[i] = cp[2];
5964774Storek 	}
6064774Storek 	return (0);
6164774Storek }
6264774Storek 
6364774Storek /*
6464774Storek  * Implement the software portion of an FBIOPUTCMAP-like ioctl.
6564774Storek  */
6664774Storek int
bt_putcmap(p,cm,cmsize)6764774Storek bt_putcmap(p, cm, cmsize)
6864774Storek 	register struct fbcmap *p;
6964774Storek 	union bt_cmap *cm;
7064774Storek 	int cmsize;
7164774Storek {
7264774Storek 	register u_int i, start, count;
7364774Storek 	register u_char *cp;
7464774Storek 
7564774Storek 	start = p->index;
7664774Storek 	count = p->count;
7764774Storek 	if (start >= cmsize || start + count > cmsize)
7864774Storek 		return (EINVAL);
7964774Storek 	if (!useracc(p->red, count, B_READ) ||
8064774Storek 	    !useracc(p->green, count, B_READ) ||
8164774Storek 	    !useracc(p->blue, count, B_READ))
8264774Storek 		return (EFAULT);
8364774Storek 	for (cp = &cm->cm_map[start][0], i = 0; i < count; cp += 3, i++) {
8464774Storek 		cp[0] = p->red[i];
8564774Storek 		cp[1] = p->green[i];
8664774Storek 		cp[2] = p->blue[i];
8764774Storek 	}
8864774Storek 	return (0);
8964774Storek }
90