xref: /original-bsd/sys/hp/dev/hil_subr.c (revision 333da485)
1 /*-
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1982, 1986, 1991, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.proprietary.c%
7  *
8  * from: Utah $Hdr: hil_subr.c 1.1 91/11/19$
9  *
10  *	@(#)hil_subr.c	8.2 (Berkeley) 01/12/94
11  */
12 
13 #include <sys/param.h>
14 #include <sys/systm.h>
15 #include <sys/ioctl.h>
16 #include <sys/tty.h>
17 #include <sys/clist.h>
18 
19 #include <hp/dev/hilreg.h>
20 
21 /*
22  * XXX this file only exists to separate out the AT&T tainted code.
23  */
24 
25 /*
26  * This is just a copy of the virgin q_to_b routine with minor
27  * optimizations for HIL use.  It is used because we don't have
28  * to raise the priority to spltty() for most of the clist manipulations.
29  */
30 hilq_to_b(q, cp, cc)
31 	register struct clist *q;
32 	register char *cp;
33 	int cc;
34 {
35 	register struct cblock *bp;
36 	register int nc;
37 	char *acp;
38 	int s;
39 	extern char cwaiting;
40 
41 	if (cc <= 0)
42 		return (0);
43 	s = splhil();
44 	if (q->c_cc <= 0) {
45 		q->c_cc = 0;
46 		q->c_cf = q->c_cl = NULL;
47 		splx(s);
48 		return (0);
49 	}
50 	acp = cp;
51 
52 	while (cc) {
53 		nc = sizeof (struct cblock) - ((int)q->c_cf & CROUND);
54 		nc = min(nc, cc);
55 		nc = min(nc, q->c_cc);
56 		(void) bcopy(q->c_cf, cp, (unsigned)nc);
57 		q->c_cf += nc;
58 		q->c_cc -= nc;
59 		cc -= nc;
60 		cp += nc;
61 		if (q->c_cc <= 0) {
62 			bp = (struct cblock *)(q->c_cf - 1);
63 			bp = (struct cblock *)((int)bp & ~CROUND);
64 			q->c_cf = q->c_cl = NULL;
65 			spltty();
66 			bp->c_next = cfreelist;
67 			cfreelist = bp;
68 			cfreecount += CBSIZE;
69 			if (cwaiting) {
70 				wakeup(&cwaiting);
71 				cwaiting = 0;
72 			}
73 			break;
74 		}
75 		if (((int)q->c_cf & CROUND) == 0) {
76 			bp = (struct cblock *)(q->c_cf);
77 			bp--;
78 			q->c_cf = bp->c_next->c_info;
79 			spltty();
80 			bp->c_next = cfreelist;
81 			cfreelist = bp;
82 			cfreecount += CBSIZE;
83 			if (cwaiting) {
84 				wakeup(&cwaiting);
85 				cwaiting = 0;
86 			}
87 			splhil();
88 		}
89 	}
90 	splx(s);
91 	return (cp-acp);
92 }
93 
94