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