sysmacros.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_SYSMACROS_H
#define _SYS_SYSMACROS_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Some macros for units conversion
*/
/*
* Disk blocks (sectors) and bytes.
*/
/* common macros */
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#endif
#ifndef ABS
#define ABS(a) ((a) < 0 ? -(a) : (a))
#endif
#ifdef _KERNEL
/*
*/
extern unsigned char byte_to_bcd[256];
extern unsigned char bcd_to_byte[256];
#endif /* _KERNEL */
/*
* WARNING: The device number macros defined here should not be used by device
* drivers or user software. Device drivers should use the device functions
* should make use of the library routines available in makedev(3). A set of
* new device macros are provided to operate on the expanded device number
* format supported in SVR4. Macro versions of the DDI device functions are
* provided for use by kernel proper routines only. Macro routines bmajor(),
* major(), minor(), emajor(), eminor(), and makedev() will be removed or
* their definitions changed at the next major release following SVR4.
*/
/* For 3b2 hardware devices the minor is */
/* restricted to 256 (0-255) */
#ifdef _LP64
#else
#define L_BITSMAJOR L_BITSMAJOR32
#define L_BITSMINOR L_BITSMINOR32
#define L_MAXMAJ L_MAXMAJ32
#define L_MAXMIN L_MAXMIN32
#endif
#ifdef _KERNEL
/* major part of a device internal to the kernel */
/* get internal major part of expanded device number */
/* minor part of a device internal to the kernel */
/* get internal minor part of expanded device number */
#else
/* major part of a device external from the kernel (same as emajor below) */
/* minor part of a device external from the kernel (same as eminor below) */
#endif /* _KERNEL */
/* create old device number */
/* make an new device number */
/*
*/
#define emajor(x) \
#define eminor(x) \
/*
* get external major and minor device
* components from expanded device number
*/
/*
* These are versions of the kernel routines for compressing and
* expanding long device numbers that don't return errors.
*/
#define DEVCMPL(x) (x)
#define DEVEXPL(x) (x)
#else
#define DEVCMPL(x) \
#define DEVEXPL(x) \
#endif /* L_BITSMAJOR32 ... */
/* convert to old (SVR3.2) dev format */
#define cmpdev(x) \
/* convert to new (SVR4) dev format */
#define expdev(x) \
((x) & O_MAXMIN))
/*
* Macro for checking power of 2 address alignment.
*/
/*
* Macros for counting and rounding.
*/
#define howmany(x, y) (((x)+((y)-1))/(y))
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
/*
* Macro to determine if value is a power of 2
*/
#define ISP2(x) (((x) & ((x) - 1)) == 0)
/*
* Macros for various sorts of alignment and rounding when the alignment
* is known to be a power of 2.
*/
/*
* Determine whether two numbers have the same high-order bit.
*/
#define P2SAMEHIGHBIT(x, y) (((x) ^ (y)) < ((x) & (y)))
/*
* Typed version of the P2* macros. These macros should be used to ensure
* that the result is correctly calculated based on the data type of (x),
* which is passed in as the last argument, regardless of the data
* type of the alignment. For example, if (x) is of type uint64_t,
* and we want to round it up to a page boundary using "PAGESIZE" as
* the alignment, we can do either
* P2ROUNDUP(x, (uint64_t)PAGESIZE)
* or
* P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
*/
#define P2SAMEHIGHBIT_TYPED(x, y, type) \
/*
* must be pointers.
*/
/* avoid any possibility of clashing with <stddef.h> version */
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SYSMACROS_H */