9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 /*
26 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 /*
31 * UNIX Device Driver Interface functions
32 *
33 * This file contains functions that are to be added to the kernel
34 * to put the interface presented to drivers in conformance with
35 * the DDI standard. Of the functions added to the kernel, 17 are
36 * function equivalents of existing macros in sysmacros.h,
37 * stream.h, and param.h
38 *
39 * 17 additional functions -- drv_getparm(), drv_setparm(),
40 * getrbuf(), freerbuf(),
41 * getemajor(), geteminor(), etoimajor(), itoemajor(), drv_usectohz(),
42 * drv_hztousec(), drv_usecwait(), drv_priv(), and kvtoppid() --
43 * are specified by DDI to exist in the kernel and are implemented here.
44 *
45 * Note that putnext() and put() are not in this file. The C version of
46 * these routines are in uts/common/os/putnext.c and assembly versions
47 * might exist for some architectures.
48 */
443 if (ticks > MAXCLOCK_T / usec_per_tick)
444 return (MAXCLOCK_T);
445
446 return (TICK_TO_USEC(ticks));
447 }
448
449
450 /*
451 * Convert from microseconds to system time units (hz), rounded up.
452 *
453 * If ticks <= 0, return 0.
454 * Otherwise, convert microseconds to ticks, rounding up.
455 */
456 clock_t
457 drv_usectohz(clock_t microsecs)
458 {
459 if (microsecs <= 0)
460 return (0);
461
462 return (USEC_TO_TICK_ROUNDUP(microsecs));
463 }
464
465 #ifdef sun
466 /*
467 * drv_usecwait implemented in each architecture's machine
468 * specific code somewhere. For sparc, it is the alternate entry
469 * to usec_delay (eventually usec_delay goes away). See
470 * sparc/os/ml/sparc_subr.s
471 */
472 #endif
473
474 /*
475 * bcanputnext, canputnext assume called from timeout, bufcall,
476 * or esballoc free routines. since these are driven by
477 * clock interrupts, instead of system calls the appropriate plumbing
478 * locks have not been acquired.
479 */
480 int
481 bcanputnext(queue_t *q, unsigned char band)
482 {
|
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 /*
26 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29 /*
30 * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
31 */
32
33 /*
34 * UNIX Device Driver Interface functions
35 *
36 * This file contains functions that are to be added to the kernel
37 * to put the interface presented to drivers in conformance with
38 * the DDI standard. Of the functions added to the kernel, 17 are
39 * function equivalents of existing macros in sysmacros.h,
40 * stream.h, and param.h
41 *
42 * 17 additional functions -- drv_getparm(), drv_setparm(),
43 * getrbuf(), freerbuf(),
44 * getemajor(), geteminor(), etoimajor(), itoemajor(), drv_usectohz(),
45 * drv_hztousec(), drv_usecwait(), drv_priv(), and kvtoppid() --
46 * are specified by DDI to exist in the kernel and are implemented here.
47 *
48 * Note that putnext() and put() are not in this file. The C version of
49 * these routines are in uts/common/os/putnext.c and assembly versions
50 * might exist for some architectures.
51 */
446 if (ticks > MAXCLOCK_T / usec_per_tick)
447 return (MAXCLOCK_T);
448
449 return (TICK_TO_USEC(ticks));
450 }
451
452
453 /*
454 * Convert from microseconds to system time units (hz), rounded up.
455 *
456 * If ticks <= 0, return 0.
457 * Otherwise, convert microseconds to ticks, rounding up.
458 */
459 clock_t
460 drv_usectohz(clock_t microsecs)
461 {
462 if (microsecs <= 0)
463 return (0);
464
465 return (USEC_TO_TICK_ROUNDUP(microsecs));
466 }
467
468 /*
469 * Convert from seconds to system time units (hz).
470 *
471 * If secs <= 0, return 0.
472 * Otherwise, convert seconds to ticks, rounding up.
473 */
474 clock_t
475 drv_sectohz(clock_t secs)
476 {
477 if (secs <= 0)
478 return (0);
479
480 return (SEC_TO_TICK(secs));
481 }
482
483 #ifdef sun
484 /*
485 * drv_usecwait implemented in each architecture's machine
486 * specific code somewhere. For sparc, it is the alternate entry
487 * to usec_delay (eventually usec_delay goes away). See
488 * sparc/os/ml/sparc_subr.s
489 */
490 #endif
491
492 /*
493 * bcanputnext, canputnext assume called from timeout, bufcall,
494 * or esballoc free routines. since these are driven by
495 * clock interrupts, instead of system calls the appropriate plumbing
496 * locks have not been acquired.
497 */
498 int
499 bcanputnext(queue_t *q, unsigned char band)
500 {
|