Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/avs/ns/solaris/nsc_ddi.c
+++ new/usr/src/uts/common/avs/ns/solaris/nsc_ddi.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * This file contains interface code to make the kernel look it has
28 28 * an svr4.2 ddi/ddk. It also adds a little other system dependent
29 29 * functionality that is useful for drivers lower than nsctl.
30 30 */
31 31
32 32 #include <sys/types.h>
33 33 #ifndef DS_DDICT
34 34 #include <sys/time.h> /* only DDI compliant as of 5.9 */
35 35 #endif
36 36 #include <sys/param.h>
37 37 #include <sys/errno.h>
38 38 #include <sys/kmem.h>
39 39 #include <sys/ksynch.h>
40 40 #include <sys/cmn_err.h>
41 41 #include <sys/uio.h>
42 42 #include <sys/conf.h>
43 43 #include <sys/modctl.h>
44 44 #ifndef DS_DDICT
45 45 #include <sys/vnode.h>
46 46 #endif
47 47 #include <sys/open.h>
48 48 #include <sys/ddi.h>
49 49
50 50 #include "nsc_thread.h"
51 51
52 52 #ifdef DS_DDICT
53 53 #include <sys/nsctl/contract.h>
54 54 #endif
55 55
56 56 #include <sys/nsctl/nsctl.h>
57 57 #include <sys/nsctl/nsvers.h>
58 58 #include "nskernd.h"
59 59 #include "nsc_list.h"
60 60
61 61 kmutex_t _nskern_lock;
62 62
63 63 void _nsc_stop_proc(void);
64 64 void _nsc_start_proc(void);
65 65
66 66
67 67 /*
68 68 * Solaris specific driver module interface code.
69 69 */
70 70
71 71 static struct cb_ops nskern_cb_ops = {
72 72 nulldev, /* open */
73 73 nulldev, /* close */
74 74 nodev, /* strategy */
75 75 nodev, /* print */
76 76 nodev, /* dump */
77 77 nodev, /* read */
78 78 nodev, /* write */
79 79 nodev, /* ioctl */
80 80 nodev, /* devmap routine */
81 81 nodev, /* mmap routine */
82 82 nodev, /* segmap */
83 83 nochpoll, /* chpoll */
84 84 ddi_prop_op,
85 85 0, /* not a STREAMS driver, no cb_str routine */
86 86 D_NEW | D_MP | D_64BIT, /* safe for multi-thread/multi-processor */
87 87 CB_REV,
88 88 nodev, /* aread */
89 89 nodev, /* awrite */
90 90 };
91 91
92 92 static int _nskern_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
93 93 static int _nskern_attach(dev_info_t *, ddi_attach_cmd_t);
94 94 static int _nskern_detach(dev_info_t *, ddi_detach_cmd_t);
95 95
96 96 static struct dev_ops nskern_ops = {
97 97 DEVO_REV, /* Driver build version */
98 98 0, /* device reference count */
99 99 _nskern_getinfo,
100 100 nulldev, /* identify */
101 101 nulldev, /* probe */
102 102 _nskern_attach,
103 103 _nskern_detach,
104 104 nodev, /* reset */
105 105 &nskern_cb_ops,
106 106 (struct bus_ops *)NULL
107 107 };
108 108
↓ open down ↓ |
108 lines elided |
↑ open up ↑ |
109 109 static struct modldrv nskern_ldrv = {
110 110 &mod_driverops,
111 111 "nws:Kernel Interface:" ISS_VERSION_STR,
112 112 &nskern_ops
113 113 };
114 114
115 115 static dev_info_t *nskern_dip;
116 116
117 117 static struct modlinkage nskern_modlinkage = {
118 118 MODREV_1,
119 - &nskern_ldrv,
120 - NULL
119 + { &nskern_ldrv, NULL }
121 120 };
122 121
123 122 /*
124 123 * Solaris module load time code
125 124 */
126 125
127 126 int
128 127 _init(void)
129 128 {
130 129 void nskern_init();
131 130 int err;
132 131
133 132 mutex_init(&_nskern_lock, NULL, MUTEX_DRIVER, NULL);
134 133
135 134 err = mod_install(&nskern_modlinkage);
136 135 if (err) {
137 136 mutex_destroy(&_nskern_lock);
138 137 cmn_err(CE_WARN, "nskern_init: mod_install err %d", err);
139 138 return (err);
140 139 }
141 140
142 141 nskern_init();
143 142
144 143 return (DDI_SUCCESS);
145 144 }
146 145
147 146 /*
148 147 * Solaris module unload time code
149 148 */
150 149
151 150 int
152 151 _fini(void)
153 152 {
154 153 int err;
155 154
156 155 if ((err = mod_remove(&nskern_modlinkage)) == 0) {
157 156 nskernd_stop();
158 157 _nsc_stop_proc();
159 158 nskernd_deinit();
160 159
161 160 mutex_destroy(&_nskern_lock);
162 161 }
163 162
164 163 return (err);
165 164 }
166 165
167 166 int
168 167 _info(struct modinfo *modinfop)
169 168 {
170 169 return (mod_info(&nskern_modlinkage, modinfop));
171 170 }
172 171
173 172 /*
174 173 * Attach an instance of the device. This happens before an open
175 174 * can succeed.
176 175 */
177 176
178 177 static int
179 178 _nskern_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
180 179 {
181 180 if (cmd == DDI_ATTACH) {
182 181 nskern_dip = dip;
183 182 return (DDI_SUCCESS);
184 183 } else {
185 184 return (DDI_FAILURE);
186 185 }
187 186 }
188 187
189 188 /* ARGSUSED */
190 189
191 190 static int
192 191 _nskern_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
193 192 {
194 193 if (cmd == DDI_DETACH) {
195 194 nskern_dip = NULL;
196 195 return (DDI_SUCCESS);
197 196 } else {
198 197 return (DDI_FAILURE);
199 198 }
200 199 }
201 200
202 201 /* ARGSUSED */
203 202 static int
204 203 _nskern_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
205 204 {
206 205 int rc = DDI_FAILURE;
207 206
208 207 switch (cmd) {
209 208 case DDI_INFO_DEVT2DEVINFO:
210 209 *result = nskern_dip;
211 210 rc = DDI_SUCCESS;
212 211 break;
213 212
214 213 case DDI_INFO_DEVT2INSTANCE:
215 214 /* single instance */
216 215 *result = 0;
217 216 rc = DDI_SUCCESS;
218 217 break;
219 218 }
220 219
221 220 return (rc);
222 221 }
223 222
224 223 /* ARGSUSED */
225 224
226 225 int
227 226 _nskern_print(dev_t dev, char *s)
228 227 {
229 228 cmn_err(CE_WARN, "nskern:%s", s);
230 229 return (0);
231 230 }
232 231
233 232 /*
234 233 * nskern_init - initialize the nskern layer at module load time.
235 234 */
236 235
237 236 void
238 237 nskern_init(void)
239 238 {
240 239 _nsc_start_proc();
241 240 nskernd_init();
242 241
243 242 (void) nst_startup();
244 243 }
245 244
246 245
247 246 #if (defined(DS_DDICT))
248 247 static clock_t
249 248 nskern_lbolt(void)
250 249 {
251 250 #ifdef _SunOS_5_6
252 251 clock_t lbolt;
253 252
254 253 if (drv_getparm(LBOLT, &lbolt) == 0)
255 254 return (lbolt);
256 255
257 256 return (0);
258 257 #else
259 258 return (ddi_get_lbolt());
260 259 #endif
261 260 }
262 261 #endif /* ddict */
263 262
264 263
265 264 /*
266 265 * nsc_usec()
267 266 * - return the value of the "microsecond timer emulation".
268 267 *
269 268 * Pre-SunOS 5.9:
270 269 * Actually this is a fake free running counter based on the lbolt value.
271 270 *
272 271 * SunOS 5.9+
273 272 * This is based on the gethrtime(9f) DDI facility.
274 273 */
275 274
276 275 #if (defined(DS_DDICT))
277 276 /* these two #defines need to match! */
278 277 #define USEC_SHIFT 16
279 278 #define INCR_TYPE uint16_t
280 279 #endif /* ! _SunOS_5_9+ */
281 280
282 281 clock_t
283 282 nsc_usec(void)
284 283 {
285 284 /* avoid divide by zero */
286 285 return (gethrtime() / 1000);
287 286 }
288 287
289 288
290 289 /*
291 290 * nsc_yield - yield the cpu.
292 291 */
293 292 void
294 293 nsc_yield(void)
295 294 {
296 295 /* can't call yield() unless there is an lwp context */
297 296 /* do this for now */
298 297
299 298 delay(2);
300 299 }
301 300
302 301
303 302 /*
304 303 * void
305 304 * ls_ins_before(ls_elt_t *, ls_elt_t *)
306 305 * Link new into list before old.
307 306 *
308 307 * Calling/Exit State:
309 308 * None.
310 309 */
311 310 #ifdef lint
312 311 void
313 312 nsc_ddi_ls_ins_before(ls_elt_t *old, ls_elt_t *new)
314 313 #else
315 314 void
316 315 ls_ins_before(ls_elt_t *old, ls_elt_t *new)
317 316 #endif
318 317 {
319 318 new->ls_prev = old->ls_prev;
320 319 new->ls_next = old;
321 320 new->ls_prev->ls_next = new;
322 321 new->ls_next->ls_prev = new;
323 322 }
324 323
325 324 /*
326 325 * void
327 326 * ls_ins_after(ls_elt_t *, ls_elt_t *)
328 327 * Link new into list after old.
329 328 *
330 329 * Calling/Exit State:
331 330 * None.
332 331 */
333 332 #ifdef lint
334 333 void
335 334 nsc_ddi_ls_ins_after(ls_elt_t *old, ls_elt_t *new)
336 335 #else
337 336 void
338 337 ls_ins_after(ls_elt_t *old, ls_elt_t *new)
339 338 #endif
340 339 {
341 340 new->ls_next = old->ls_next;
342 341 new->ls_prev = old;
343 342 new->ls_next->ls_prev = new;
344 343 new->ls_prev->ls_next = new;
345 344 }
346 345
347 346 /*
348 347 * ls_elt_t *
349 348 * ls_remque(ls_elt_t *)
350 349 * Unlink first element in the specified list.
351 350 *
352 351 * Calling/Exit State:
353 352 * Returns the element's address or 0 if list is empty.
354 353 * Resets elements pointers to empty list state.
355 354 */
356 355 ls_elt_t *
357 356 ls_remque(ls_elt_t *p)
358 357 {
359 358 ls_elt_t *result = 0;
360 359
361 360 if (!LS_ISEMPTY(p)) {
362 361 result = p->ls_next;
363 362 result->ls_prev->ls_next = result->ls_next;
364 363 result->ls_next->ls_prev = result->ls_prev;
365 364 LS_INIT(result);
366 365 }
367 366 return (result);
368 367 }
369 368
370 369 /*
371 370 * void
372 371 * ls_remove(ls_elt_t *)
373 372 * Unlink donated element for list.
374 373 *
375 374 * Calling/Exit State:
376 375 * Resets elements pointers to empty list state.
377 376 */
378 377 #ifdef lint
379 378 void
380 379 nsc_ddi_ls_remove(ls_elt_t *p)
381 380 #else
382 381 void
383 382 ls_remove(ls_elt_t *p)
384 383 #endif
385 384 {
386 385 p->ls_prev->ls_next = p->ls_next;
387 386 p->ls_next->ls_prev = p->ls_prev;
388 387 LS_INIT(p);
389 388 }
↓ open down ↓ |
259 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX