FreeBSD/Linux Kernel Cross Reference
sys/device/subrs.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1991,1990,1989,1988 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: subrs.c,v $
29 * Revision 2.16 93/11/17 16:34:42 dbg
30 * ANSI-fied.
31 * [93/06/16 dbg]
32 *
33 * Revision 2.15 93/03/09 10:54:20 danner
34 * Removed string routines, and the Berkeley copyright that came
35 * with them. The new ones we wrote now live in kern/strings.[ch].
36 * [93/03/06 af]
37 *
38 * Revision 2.14 93/01/14 17:27:17 danner
39 * 64bit cleanup.
40 * [92/11/30 af]
41 *
42 * Revision 2.13 92/08/03 17:33:57 jfriedl
43 * removed silly prototypes
44 * [92/08/02 jfriedl]
45 *
46 * Revision 2.12 92/05/21 17:09:49 jfriedl
47 * Cleanup to quiet gcc warnings. Replaced strlen with a faster one.
48 * [92/05/16 jfriedl]
49 *
50 * Revision 2.11 91/09/12 16:37:39 bohman
51 * Added strlen() (BSD version).
52 * [91/09/11 17:07:25 bohman]
53 *
54 * Revision 2.10 91/08/24 11:56:04 af
55 * Use BSD string functions now, which of course come with a
56 * copyright. Also, undef them in case some smarty..
57 * [91/08/22 af]
58 *
59 * Revision 2.9 91/07/31 17:34:27 dbg
60 * Add strcpy.
61 * [91/07/30 16:47:37 dbg]
62 *
63 * Revision 2.8 91/05/14 16:01:30 mrt
64 * Correcting copyright
65 *
66 * Revision 2.7 91/03/16 14:43:34 rpd
67 * Updated for new kmem_alloc interface.
68 * [91/03/03 rpd]
69 *
70 * Revision 2.6 91/02/05 17:10:17 mrt
71 * Changed to new Mach copyright
72 * [91/01/31 17:30:39 mrt]
73 *
74 * Revision 2.5 91/01/08 15:10:02 rpd
75 * Added continuation argument to thread_block.
76 * [90/12/08 rpd]
77 *
78 * Revision 2.4 90/05/03 15:19:27 dbg
79 * Add compatibility routines for BSD-compatible device drivers:
80 * sleep, wakeup, geteblk, brelse.
81 * [90/03/14 dbg]
82 *
83 * Revision 2.3 90/01/11 11:42:31 dbg
84 * De-linted.
85 * [89/12/15 dbg]
86 *
87 * Add lock initialization in if_init_queues.
88 * [89/11/30 dbg]
89 *
90 * Revision 2.2 89/11/29 14:08:58 af
91 * RCS-ed, added strncmp (needed for scsi label comparisons).
92 * [89/10/28 af]
93 *
94 */
95 /*
96 * Random device subroutines and stubs.
97 */
98
99 #include <kern/kern_io.h>
100 #include <kern/sched_prim.h>
101 #include <vm/vm_kern.h>
102 #include <vm/vm_user.h>
103 #include <device/buf.h>
104 #include <device/if_hdr.h>
105 #include <device/if_ether.h>
106
107
108
109 /*
110 * Print out disk name and block number for hard disk errors.
111 */
112 void harderr(
113 struct buf *bp,
114 char * cp)
115 {
116 printf("%s%d%c: hard error sn%d ",
117 cp,
118 minor(bp->b_dev) >> 3,
119 'a' + (minor(bp->b_dev) & 0x7),
120 bp->b_blkno);
121 }
122
123 /*
124 * Ethernet support routines.
125 */
126 u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
127
128 /*
129 * Convert Ethernet address to printable (loggable) representation.
130 */
131 char *
132 ether_sprintf(
133 register u_char *ap)
134 {
135 register i;
136 static char etherbuf[18];
137 register char *cp = etherbuf;
138 static char digits[] = "0123456789abcdef";
139
140 for (i = 0; i < 6; i++) {
141 *cp++ = digits[*ap >> 4];
142 *cp++ = digits[*ap++ & 0xf];
143 *cp++ = ':';
144 }
145 *--cp = 0;
146 return etherbuf;
147 }
148
149 /*
150 * Initialize send and receive queues on an interface.
151 */
152 void if_init_queues(
153 register struct ifnet *ifp)
154 {
155 IFQ_INIT(&ifp->if_snd);
156 queue_init(&ifp->if_rcv_port_list);
157 simple_lock_init(&ifp->if_rcv_port_list_lock);
158 }
159
160
161 /*
162 * Compatibility with BSD device drivers.
163 */
164 void sleep(
165 void * channel,
166 int priority)
167 {
168 assert_wait((event_t) channel, FALSE); /* not interruptible XXX */
169 thread_block(CONTINUE_NULL);
170 }
171
172 void wakeup(
173 void * channel)
174 {
175 thread_wakeup((event_t) channel);
176 }
177
178 struct buf *
179 geteblk(
180 int size)
181 {
182 register io_req_t ior;
183
184 io_req_alloc(ior, 0);
185 ior->io_device = (device_t)0;
186 ior->io_unit = 0;
187 ior->io_op = 0;
188 ior->io_mode = 0;
189 ior->io_recnum = 0;
190 ior->io_count = size;
191 ior->io_residual = 0;
192 ior->io_error = 0;
193
194 size = round_page(size);
195 ior->io_alloc_size = size;
196 if (kmem_alloc(kernel_map, (vm_offset_t *)&ior->io_data, size)
197 != KERN_SUCCESS)
198 panic("geteblk");
199
200 return ior;
201 }
202
203 void brelse(
204 struct buf *bp)
205 {
206 register io_req_t ior = bp;
207
208 (void) vm_deallocate(kernel_map,
209 (vm_offset_t) ior->io_data,
210 (vm_size_t) ior->io_alloc_size);
211 io_req_free(ior);
212 }
Cache object: cac8edf11b5fa9f0d11d45a3a56fc46d
|