]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_misc.c
75c735bccf1a6cd5ddb334bc2e34829625b22dbd
[apple/xnu.git] / bsd / netat / adsp_misc.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 #include <sys/errno.h>
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <machine/spl.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/proc.h>
37 #include <sys/filedesc.h>
38 #include <sys/fcntl.h>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41
42 #include <netat/sysglue.h>
43 #include <netat/appletalk.h>
44 #include <netat/at_pcb.h>
45 #include <netat/debug.h>
46 #include <netat/adsp.h>
47 #include <netat/adsp_internal.h>
48
49 /*
50 * These function replace the Mk68 assembly routines found in qAddToEnd.s and
51 * q????.s
52 * Modified for MP, 1996 by Tuyen Nguyen
53 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
54 */
55
56
57 struct qlink {
58 struct qlink *qlinkp;
59 };
60
61 /* ----------------------------------------------------------------------
62 * void qAddToEnd(void *qhead, void *qelem)
63 *
64 * INPUTS:
65 * Ptr to ptr to 1st item in queue
66 * Ptr to item to add to end of queue
67 * OUTPUTS:
68 * none
69 *
70 * Assumptions: The link field is the FIRST field of the qelem structure.
71 * ----------------------------------------------------------------------
72 */
73 int qAddToEnd(qhead, qelem)
74 struct qlink **qhead;
75 struct qlink *qelem;
76 {
77 /* define our own type to access the next field. NOTE THAT THE "NEXT"
78 * FIELD IS ASSUMED TO BE THE FIRST FIELD OF THE STRUCTURE
79 */
80
81 register struct qlink *q;
82
83 /* Scan the linked list to the end and update the previous
84 * element next field. (do that protocted).
85 */
86
87 q = *qhead;
88 if (q) {
89 while (q->qlinkp) {
90 /* are we about to link to ourself */
91 if (q == qelem)
92 goto breakit;
93 q = q->qlinkp;
94 }
95 q->qlinkp = qelem;
96 }
97 else {
98 *qhead = qelem;
99 }
100 qelem->qlinkp = (struct qlink *) 0;
101 breakit:
102 #ifdef NOTDEF
103 DPRINTF("%s: qhead=%x added elem=%x\n","qAddToEnd", qhead, qelem);
104 #endif
105 return 0;
106 }
107
108
109
110 /* ----------------------------------------------------------------------
111 * qfind_m
112 * void* qfind_m(void *qhead, void NPTR match, ProcPtr compare_fnx)
113 *
114 * Hunt down a linked list of queue elements calling the compare
115 * function on each item. When the compare function returns true,
116 * return ptr to the queue element.
117 *
118 *
119 * INPUTS:
120 * qhead Address of ptr to first item in queue
121 * match
122 * compare_fnx
123 * OUTPUTS:
124 * D0 & A0 Ptr to queue element or NIL
125 * REGISTERS:
126 * D0,D1,A0,A1
127 * ----------------------------------------------------------------------
128 */
129 void* qfind_m(qhead, match, compare_fnx)
130 CCBPtr qhead;
131 void *match;
132 ProcPtr compare_fnx;
133 {
134 CCBPtr queue_item = qhead;
135
136 while (queue_item) {
137 if ((*compare_fnx)(queue_item,match))
138 break;
139
140 queue_item = queue_item->ccbLink;
141 }
142
143 return (queue_item);
144 }