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