xref: /xnu-8792.61.2/bsd/arm/param.h (revision 42e220869062b56f8d7d0726fd4c88954f87902c)
1*42e22086SApple OSS Distributions /*
2*42e22086SApple OSS Distributions  * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
3*42e22086SApple OSS Distributions  */
4*42e22086SApple OSS Distributions /*-
5*42e22086SApple OSS Distributions  * Copyright (c) 1990, 1993
6*42e22086SApple OSS Distributions  *	The Regents of the University of California.  All rights reserved.
7*42e22086SApple OSS Distributions  * (c) UNIX System Laboratories, Inc.
8*42e22086SApple OSS Distributions  * All or some portions of this file are derived from material licensed
9*42e22086SApple OSS Distributions  * to the University of California by American Telephone and Telegraph
10*42e22086SApple OSS Distributions  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11*42e22086SApple OSS Distributions  * the permission of UNIX System Laboratories, Inc.
12*42e22086SApple OSS Distributions  *
13*42e22086SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
14*42e22086SApple OSS Distributions  * modification, are permitted provided that the following conditions
15*42e22086SApple OSS Distributions  * are met:
16*42e22086SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
17*42e22086SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
18*42e22086SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
19*42e22086SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
20*42e22086SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
21*42e22086SApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
22*42e22086SApple OSS Distributions  *    must display the following acknowledgement:
23*42e22086SApple OSS Distributions  *	This product includes software developed by the University of
24*42e22086SApple OSS Distributions  *	California, Berkeley and its contributors.
25*42e22086SApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
26*42e22086SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
27*42e22086SApple OSS Distributions  *    without specific prior written permission.
28*42e22086SApple OSS Distributions  *
29*42e22086SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30*42e22086SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31*42e22086SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32*42e22086SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33*42e22086SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34*42e22086SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35*42e22086SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36*42e22086SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37*42e22086SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38*42e22086SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39*42e22086SApple OSS Distributions  * SUCH DAMAGE.
40*42e22086SApple OSS Distributions  *
41*42e22086SApple OSS Distributions  *	@(#)param.h	8.1 (Berkeley) 4/4/95
42*42e22086SApple OSS Distributions  */
43*42e22086SApple OSS Distributions 
44*42e22086SApple OSS Distributions /*
45*42e22086SApple OSS Distributions  * Machine dependent constants for ARM
46*42e22086SApple OSS Distributions  */
47*42e22086SApple OSS Distributions 
48*42e22086SApple OSS Distributions #ifndef _ARM_PARAM_H_
49*42e22086SApple OSS Distributions #define _ARM_PARAM_H_
50*42e22086SApple OSS Distributions 
51*42e22086SApple OSS Distributions #if defined (__arm__) || defined (__arm64__)
52*42e22086SApple OSS Distributions 
53*42e22086SApple OSS Distributions #include <arm/_param.h>
54*42e22086SApple OSS Distributions 
55*42e22086SApple OSS Distributions /*
56*42e22086SApple OSS Distributions  * Round p (pointer or byte index) up to a correctly-aligned value for all
57*42e22086SApple OSS Distributions  * data types (int, long, ...).   The result is unsigned int and must be
58*42e22086SApple OSS Distributions  * cast to any desired pointer type.
59*42e22086SApple OSS Distributions  */
60*42e22086SApple OSS Distributions #define ALIGNBYTES      __DARWIN_ALIGNBYTES
61*42e22086SApple OSS Distributions #define ALIGN(p)        __DARWIN_ALIGN(p)
62*42e22086SApple OSS Distributions 
63*42e22086SApple OSS Distributions #define NBPG            4096            /* bytes/page */
64*42e22086SApple OSS Distributions #define PGOFSET         (NBPG-1)        /* byte offset into page */
65*42e22086SApple OSS Distributions #define PGSHIFT         12              /* LOG2(NBPG) */
66*42e22086SApple OSS Distributions 
67*42e22086SApple OSS Distributions #define DEV_BSIZE       512
68*42e22086SApple OSS Distributions #define DEV_BSHIFT      9               /* log2(DEV_BSIZE) */
69*42e22086SApple OSS Distributions #define BLKDEV_IOSIZE   2048
70*42e22086SApple OSS Distributions #define MAXPHYS         (64 * 1024)     /* max raw I/O transfer size */
71*42e22086SApple OSS Distributions 
72*42e22086SApple OSS Distributions #define CLSIZE          1
73*42e22086SApple OSS Distributions #define CLSIZELOG2      0
74*42e22086SApple OSS Distributions 
75*42e22086SApple OSS Distributions /*
76*42e22086SApple OSS Distributions  * Constants related to network buffer management.
77*42e22086SApple OSS Distributions  * MCLBYTES must be no larger than CLBYTES (the software page size), and,
78*42e22086SApple OSS Distributions  * on machines that exchange pages of input or output buffers with mbuf
79*42e22086SApple OSS Distributions  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
80*42e22086SApple OSS Distributions  * of the hardware page size.
81*42e22086SApple OSS Distributions  */
82*42e22086SApple OSS Distributions #define MSIZESHIFT      8                       /* 256 */
83*42e22086SApple OSS Distributions #define MSIZE           (1 << MSIZESHIFT)       /* size of an mbuf */
84*42e22086SApple OSS Distributions #define MCLSHIFT        11                      /* 2048 */
85*42e22086SApple OSS Distributions #define MCLBYTES        (1 << MCLSHIFT)         /* size of an mbuf cluster */
86*42e22086SApple OSS Distributions #define MBIGCLSHIFT     12                      /* 4096 */
87*42e22086SApple OSS Distributions #define MBIGCLBYTES     (1 << MBIGCLSHIFT)      /* size of a big cluster */
88*42e22086SApple OSS Distributions #define M16KCLSHIFT     14                      /* 16384 */
89*42e22086SApple OSS Distributions #define M16KCLBYTES     (1 << M16KCLSHIFT)      /* size of a jumbo cluster */
90*42e22086SApple OSS Distributions 
91*42e22086SApple OSS Distributions #define MCLOFSET        (MCLBYTES - 1)
92*42e22086SApple OSS Distributions #ifndef NMBCLUSTERS
93*42e22086SApple OSS Distributions #define NMBCLUSTERS     CONFIG_NMBCLUSTERS      /* cl map size */
94*42e22086SApple OSS Distributions #endif
95*42e22086SApple OSS Distributions 
96*42e22086SApple OSS Distributions /*
97*42e22086SApple OSS Distributions  * Some macros for units conversion
98*42e22086SApple OSS Distributions  */
99*42e22086SApple OSS Distributions /* Core clicks (NeXT_page_size bytes) to segments and vice versa */
100*42e22086SApple OSS Distributions #define ctos(x) (x)
101*42e22086SApple OSS Distributions #define stoc(x) (x)
102*42e22086SApple OSS Distributions 
103*42e22086SApple OSS Distributions /* Core clicks (4096 bytes) to disk blocks */
104*42e22086SApple OSS Distributions #define ctod(x) ((x)<<(PGSHIFT-DEV_BSHIFT))
105*42e22086SApple OSS Distributions #define dtoc(x) ((x)>>(PGSHIFT-DEV_BSHIFT))
106*42e22086SApple OSS Distributions #define dtob(x) ((x)<<DEV_BSHIFT)
107*42e22086SApple OSS Distributions 
108*42e22086SApple OSS Distributions /* clicks to bytes */
109*42e22086SApple OSS Distributions #define ctob(x) ((x)<<PGSHIFT)
110*42e22086SApple OSS Distributions 
111*42e22086SApple OSS Distributions /* bytes to clicks */
112*42e22086SApple OSS Distributions #define btoc(x) (((unsigned)(x)+(NBPG-1))>>PGSHIFT)
113*42e22086SApple OSS Distributions 
114*42e22086SApple OSS Distributions #ifdef __APPLE__
115*42e22086SApple OSS Distributions #define  btodb(bytes, devBlockSize)         \
116*42e22086SApple OSS Distributions 	((unsigned)(bytes) / devBlockSize)
117*42e22086SApple OSS Distributions #define  dbtob(db, devBlockSize)            \
118*42e22086SApple OSS Distributions 	((unsigned)(db) * devBlockSize)
119*42e22086SApple OSS Distributions #else
120*42e22086SApple OSS Distributions #define btodb(bytes)                    /* calculates (bytes / DEV_BSIZE) */ \
121*42e22086SApple OSS Distributions 	((unsigned)(bytes) >> DEV_BSHIFT)
122*42e22086SApple OSS Distributions #define dbtob(db)                       /* calculates (db * DEV_BSIZE) */ \
123*42e22086SApple OSS Distributions 	((unsigned)(db) << DEV_BSHIFT)
124*42e22086SApple OSS Distributions #endif
125*42e22086SApple OSS Distributions 
126*42e22086SApple OSS Distributions /*
127*42e22086SApple OSS Distributions  * Map a ``block device block'' to a file system block.
128*42e22086SApple OSS Distributions  * This should be device dependent, and will be if we
129*42e22086SApple OSS Distributions  * add an entry to cdevsw/bdevsw for that purpose.
130*42e22086SApple OSS Distributions  * For now though just use DEV_BSIZE.
131*42e22086SApple OSS Distributions  */
132*42e22086SApple OSS Distributions #define bdbtofsb(bn)    ((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
133*42e22086SApple OSS Distributions 
134*42e22086SApple OSS Distributions /*
135*42e22086SApple OSS Distributions  * Macros to decode (and encode) processor status word.
136*42e22086SApple OSS Distributions  */
137*42e22086SApple OSS Distributions #define STATUS_WORD(rpl, ipl)   (((ipl) << 8) | (rpl))
138*42e22086SApple OSS Distributions #define USERMODE(x)             (((x) & 3) == 3)
139*42e22086SApple OSS Distributions #define BASEPRI(x)              (((x) & (255 << 8)) == 0)
140*42e22086SApple OSS Distributions 
141*42e22086SApple OSS Distributions 
142*42e22086SApple OSS Distributions #if     defined(KERNEL) || defined(STANDALONE)
143*42e22086SApple OSS Distributions #define DELAY(n) delay(n)
144*42e22086SApple OSS Distributions 
145*42e22086SApple OSS Distributions #else   /* defined(KERNEL) || defined(STANDALONE) */
146*42e22086SApple OSS Distributions #define DELAY(n)        { int N = (n); while (--N > 0); }
147*42e22086SApple OSS Distributions #endif  /* defined(KERNEL) || defined(STANDALONE) */
148*42e22086SApple OSS Distributions 
149*42e22086SApple OSS Distributions #endif /* defined (__arm__) || defined (__arm64__) */
150*42e22086SApple OSS Distributions 
151*42e22086SApple OSS Distributions #endif /* _ARM_PARAM_H_ */
152