xref: /original-bsd/sys/hp/dev/hil_subr.c (revision e0851aa6)
1 /*-
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
4  * 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	7.3 (Berkeley) 10/11/92
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 {
34 	register struct cblock *bp;
35 	register int nc;
36 	char *acp;
37 	int s;
38 	extern char cwaiting;
39 
40 	if (cc <= 0)
41 		return (0);
42 	s = splhil();
43 	if (q->c_cc <= 0) {
44 		q->c_cc = 0;
45 		q->c_cf = q->c_cl = NULL;
46 		splx(s);
47 		return (0);
48 	}
49 	acp = cp;
50 
51 	while (cc) {
52 		nc = sizeof (struct cblock) - ((int)q->c_cf & CROUND);
53 		nc = min(nc, cc);
54 		nc = min(nc, q->c_cc);
55 		(void) bcopy(q->c_cf, cp, (unsigned)nc);
56 		q->c_cf += nc;
57 		q->c_cc -= nc;
58 		cc -= nc;
59 		cp += nc;
60 		if (q->c_cc <= 0) {
61 			bp = (struct cblock *)(q->c_cf - 1);
62 			bp = (struct cblock *)((int)bp & ~CROUND);
63 			q->c_cf = q->c_cl = NULL;
64 			spltty();
65 			bp->c_next = cfreelist;
66 			cfreelist = bp;
67 			cfreecount += CBSIZE;
68 			if (cwaiting) {
69 				wakeup(&cwaiting);
70 				cwaiting = 0;
71 			}
72 			break;
73 		}
74 		if (((int)q->c_cf & CROUND) == 0) {
75 			bp = (struct cblock *)(q->c_cf);
76 			bp--;
77 			q->c_cf = bp->c_next->c_info;
78 			spltty();
79 			bp->c_next = cfreelist;
80 			cfreelist = bp;
81 			cfreecount += CBSIZE;
82 			if (cwaiting) {
83 				wakeup(&cwaiting);
84 				cwaiting = 0;
85 			}
86 			splhil();
87 		}
88 	}
89 	splx(s);
90 	return (cp-acp);
91 }
92 
93