2008-05-26 08:38:26 +04:00
|
|
|
/*
|
|
|
|
* This file is part of the SPL: Solaris Porting Layer.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Lawrence Livermore National Security, LLC.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory
|
|
|
|
* Written by:
|
|
|
|
* Brian Behlendorf <behlendorf1@llnl.gov>,
|
|
|
|
* Herb Wartens <wartens2@llnl.gov>,
|
|
|
|
* Jim Garlick <garlick@llnl.gov>
|
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#ifndef _SPL_SYSMACROS_H
|
|
|
|
#define _SPL_SYSMACROS_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2008-04-19 03:39:58 +04:00
|
|
|
#include <sys/debug.h>
|
2008-03-08 03:18:21 +03:00
|
|
|
#include <sys/varargs.h>
|
2008-03-13 02:48:28 +03:00
|
|
|
#include <sys/zone.h>
|
2008-03-17 21:29:57 +03:00
|
|
|
#include <sys/signal.h>
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
#ifndef _KERNEL
|
|
|
|
#define _KERNEL __KERNEL__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Missing defines.
|
|
|
|
*/
|
2008-03-07 02:42:37 +03:00
|
|
|
#define FALSE 0
|
|
|
|
#define TRUE 1
|
2008-03-07 03:28:32 +03:00
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#define INT32_MAX INT_MAX
|
2008-03-07 23:48:44 +03:00
|
|
|
#define INT32_MIN INT_MIN
|
|
|
|
#define UINT32_MAX UINT_MAX
|
|
|
|
#define UINT32_MIN UINT_MIN
|
|
|
|
#define INT64_MAX LLONG_MAX
|
|
|
|
#define INT64_MIN LLONG_MIN
|
|
|
|
#define UINT64_MAX ULLONG_MAX
|
|
|
|
#define UINT64_MIN ULLONG_MIN
|
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#define NBBY 8
|
|
|
|
#define ENOTSUP ENOTSUPP
|
2008-03-07 03:28:32 +03:00
|
|
|
|
2008-03-08 03:18:21 +03:00
|
|
|
#define MAXMSGLEN 256
|
2008-03-04 21:22:31 +03:00
|
|
|
#define MAXNAMELEN 256
|
|
|
|
#define MAXPATHLEN PATH_MAX
|
2009-02-07 03:53:39 +03:00
|
|
|
|
|
|
|
#ifdef _LP64
|
2008-03-07 03:28:32 +03:00
|
|
|
#define MAXOFFSET_T 0x7fffffffffffffffl
|
2009-02-07 03:53:39 +03:00
|
|
|
#else
|
|
|
|
#define MAXOFFSET_T 0x7fffffffl
|
|
|
|
#endif
|
2008-03-07 03:28:32 +03:00
|
|
|
|
|
|
|
#define MAXBSIZE 8192
|
|
|
|
#define DEV_BSIZE 512
|
|
|
|
#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
|
|
|
|
|
2009-02-05 02:15:41 +03:00
|
|
|
#define curproc current
|
|
|
|
#define proc_pageout NULL
|
2008-03-04 21:22:31 +03:00
|
|
|
#define max_ncpus 64
|
2008-03-08 03:58:32 +03:00
|
|
|
#define CPU_SEQID smp_processor_id() /* I think... */
|
2008-03-07 03:28:32 +03:00
|
|
|
#define _NOTE(x)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2009-02-05 02:15:41 +03:00
|
|
|
|
2008-03-10 20:05:34 +03:00
|
|
|
#define RLIM64_INFINITY RLIM_INFINITY
|
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
/* 0..MAX_PRIO-1: Process priority
|
|
|
|
* 0..MAX_RT_PRIO-1: RT priority tasks
|
|
|
|
* MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
|
|
|
|
*
|
|
|
|
* Treat shim tasks as SCHED_NORMAL tasks
|
|
|
|
*/
|
|
|
|
#define minclsyspri (MAX_RT_PRIO)
|
|
|
|
#define maxclsyspri (MAX_PRIO-1)
|
|
|
|
|
|
|
|
#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
|
|
|
|
#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
|
|
|
|
|
|
|
|
/* Missing macros
|
|
|
|
*/
|
|
|
|
#define PAGESIZE PAGE_SIZE
|
|
|
|
|
|
|
|
/* from Solaris sys/byteorder.h */
|
|
|
|
#define BSWAP_8(x) ((x) & 0xff)
|
|
|
|
#define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
|
|
|
|
#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
|
|
|
|
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
|
|
|
|
|
|
|
|
/* Map some simple functions.
|
|
|
|
*/
|
|
|
|
#define bzero(ptr,size) memset(ptr,0,size)
|
|
|
|
#define bcopy(src,dest,size) memcpy(dest,src,size)
|
2008-03-07 03:28:32 +03:00
|
|
|
#define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
|
2008-03-05 03:58:54 +03:00
|
|
|
|
|
|
|
/* Dtrace probes do not exist in the linux kernel */
|
2009-01-06 03:09:21 +03:00
|
|
|
#ifdef DTRACE_PROBE
|
|
|
|
#undef DTRACE_PROBE
|
|
|
|
#endif /* DTRACE_PROBE */
|
|
|
|
#define DTRACE_PROBE(a) ((void)0)
|
2008-03-05 03:58:54 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE1
|
|
|
|
#undef DTRACE_PROBE1
|
|
|
|
#endif /* DTRACE_PROBE1 */
|
2008-03-07 23:48:44 +03:00
|
|
|
#define DTRACE_PROBE1(a, b, c) ((void)0)
|
2008-03-05 03:58:54 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE2
|
|
|
|
#undef DTRACE_PROBE2
|
|
|
|
#endif /* DTRACE_PROBE2 */
|
2008-03-07 23:48:44 +03:00
|
|
|
#define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
|
2008-03-05 03:58:54 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE3
|
|
|
|
#undef DTRACE_PROBE3
|
|
|
|
#endif /* DTRACE_PROBE3 */
|
2008-03-07 23:48:44 +03:00
|
|
|
#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
|
2008-03-05 03:58:54 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE4
|
|
|
|
#undef DTRACE_PROBE4
|
|
|
|
#endif /* DTRACE_PROBE4 */
|
2008-03-07 23:48:44 +03:00
|
|
|
#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2008-03-07 02:12:55 +03:00
|
|
|
/* Missing globals */
|
2008-04-24 21:41:23 +04:00
|
|
|
extern char spl_version[16];
|
2008-04-21 21:29:47 +04:00
|
|
|
extern long spl_hostid;
|
|
|
|
extern char hw_serial[11];
|
2008-03-04 21:22:31 +03:00
|
|
|
extern int p0;
|
|
|
|
|
2008-03-07 02:12:55 +03:00
|
|
|
/* Missing misc functions */
|
|
|
|
extern int highbit(unsigned long i);
|
2009-02-19 22:26:17 +03:00
|
|
|
extern uint32_t zone_get_hostid(void *zone);
|
2009-10-02 03:06:15 +04:00
|
|
|
extern void spl_setup(void);
|
|
|
|
extern void spl_cleanup(void);
|
2008-03-07 02:12:55 +03:00
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#define makedevice(maj,min) makedev(maj,min)
|
|
|
|
|
|
|
|
/* common macros */
|
|
|
|
#ifndef MIN
|
2009-05-20 23:23:24 +04:00
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
2009-05-20 23:23:24 +04:00
|
|
|
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
#ifndef ABS
|
2009-05-20 23:23:24 +04:00
|
|
|
#define ABS(a) ((a) < 0 ? -(a) : (a))
|
|
|
|
#endif
|
|
|
|
#ifndef DIV_ROUND_UP
|
|
|
|
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
|
|
|
#endif
|
|
|
|
#ifndef roundup
|
|
|
|
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compatibility macros/typedefs needed for Solaris -> Linux port
|
|
|
|
*/
|
|
|
|
#define P2ALIGN(x, align) ((x) & -(align))
|
|
|
|
#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
|
|
|
|
#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
|
|
|
|
#define P2ROUNDUP_TYPED(x, align, type) \
|
|
|
|
(-(-(type)(x) & -(type)(align)))
|
|
|
|
#define P2PHASE(x, align) ((x) & ((align) - 1))
|
|
|
|
#define P2NPHASE(x, align) (-(x) & ((align) - 1))
|
|
|
|
#define P2NPHASE_TYPED(x, align, type) \
|
|
|
|
(-(type)(x) & ((type)(align) - 1))
|
|
|
|
#define ISP2(x) (((x) & ((x) - 1)) == 0)
|
|
|
|
#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
|
2009-01-06 20:23:13 +03:00
|
|
|
#define P2BOUNDARY(off, len, align) \
|
|
|
|
(((off) ^ ((off) + (len) - 1)) > (align) - 1)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 P2ALIGN_TYPED(x, align, type) \
|
|
|
|
((type)(x) & -(type)(align))
|
|
|
|
#define P2PHASE_TYPED(x, align, type) \
|
|
|
|
((type)(x) & ((type)(align) - 1))
|
|
|
|
#define P2NPHASE_TYPED(x, align, type) \
|
|
|
|
(-(type)(x) & ((type)(align) - 1))
|
|
|
|
#define P2ROUNDUP_TYPED(x, align, type) \
|
|
|
|
(-(-(type)(x) & -(type)(align)))
|
|
|
|
#define P2END_TYPED(x, align, type) \
|
|
|
|
(-(~(type)(x) & -(type)(align)))
|
|
|
|
#define P2PHASEUP_TYPED(x, align, phase, type) \
|
|
|
|
((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
|
|
|
|
#define P2CROSS_TYPED(x, y, align, type) \
|
|
|
|
(((type)(x) ^ (type)(y)) > (type)(align) - 1)
|
|
|
|
#define P2SAMEHIGHBIT_TYPED(x, y, type) \
|
|
|
|
(((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
|
|
|
|
|
|
|
|
#if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
|
|
|
|
|
|
|
|
/* avoid any possibility of clashing with <stddef.h> version */
|
|
|
|
|
|
|
|
#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _SPL_SYSMACROS_H */
|