xref: /freebsd-13-stable/sys/riscv/include/param.h (revision 4b40a16f0d188422227478889b38cc341d50f88f)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * William Jolitz.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	from: @(#)param.h	5.8 (Berkeley) 6/28/91
30  */
31 
32 #ifndef _MACHINE_PARAM_H_
33 #define	_MACHINE_PARAM_H_
34 
35 /*
36  * Machine dependent constants for RISC-V.
37  */
38 
39 #include <machine/_align.h>
40 
41 #define	STACKALIGNBYTES	(16 - 1)
42 #define	STACKALIGN(p)	((uint64_t)(p) & ~STACKALIGNBYTES)
43 
44 #define __PCI_REROUTE_INTERRUPT
45 
46 #ifndef MACHINE
47 #define	MACHINE		"riscv"
48 #endif
49 #ifndef MACHINE_ARCH
50 
51 /* Always use the hard-float arch for the kernel. */
52 #if !defined(_KERNEL) && defined(__riscv_float_abi_soft)
53 #define	MACHINE_ARCH	"riscv64sf"
54 #else
55 #define	MACHINE_ARCH	"riscv64"
56 #endif
57 #endif
58 #ifdef _KERNEL
59 #define	MACHINE_ARCHES	"riscv64 riscv64sf"
60 #endif
61 
62 #ifdef SMP
63 #ifndef MAXCPU
64 #define	MAXCPU		16
65 #endif
66 #else
67 #define	MAXCPU		1
68 #endif
69 
70 #ifndef MAXMEMDOM
71 #define	MAXMEMDOM	1
72 #endif
73 
74 #define	ALIGNBYTES	_ALIGNBYTES
75 #define	ALIGN(p)	_ALIGN(p)
76 /*
77  * ALIGNED_POINTER is a boolean macro that checks whether an address
78  * is valid to fetch data elements of type t from on this architecture.
79  * This does not reflect the optimal alignment, just the possibility
80  * (within reasonable limits).
81  */
82 #define	ALIGNED_POINTER(p, t)	((((u_long)(p)) & (sizeof(t) - 1)) == 0)
83 
84 /*
85  * CACHE_LINE_SIZE is the compile-time maximum cache line size for an
86  * architecture.  It should be used with appropriate caution.
87  */
88 #define	CACHE_LINE_SHIFT	6
89 #define	CACHE_LINE_SIZE		(1 << CACHE_LINE_SHIFT)
90 
91 #define	PAGE_SHIFT	12
92 #define	PAGE_SIZE	(1 << PAGE_SHIFT)	/* Page size */
93 #define	PAGE_MASK	(PAGE_SIZE - 1)
94 
95 #define	MAXPAGESIZES	3	/* maximum number of supported page sizes */
96 
97 #ifndef KSTACK_PAGES
98 #define	KSTACK_PAGES	4	/* pages of kernel stack (with pcb) */
99 #endif
100 
101 #define	KSTACK_GUARD_PAGES	1	/* pages of kstack guard; 0 disables */
102 #define	PCPU_PAGES		1
103 
104 /*
105  * Mach derived conversion macros
106  */
107 #define	round_page(x)		(((unsigned long)(x) + PAGE_MASK) & ~PAGE_MASK)
108 #define	trunc_page(x)		((unsigned long)(x) & ~PAGE_MASK)
109 
110 #define	atop(x)			((unsigned long)(x) >> PAGE_SHIFT)
111 #define	ptoa(x)			((unsigned long)(x) << PAGE_SHIFT)
112 
113 #define	riscv_btop(x)		((unsigned long)(x) >> PAGE_SHIFT)
114 #define	riscv_ptob(x)		((unsigned long)(x) << PAGE_SHIFT)
115 
116 #define	pgtok(x)		((unsigned long)(x) * (PAGE_SIZE / 1024))
117 
118 #endif /* !_MACHINE_PARAM_H_ */
119