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