param.h revision 233644
117680Spst/*	$OpenBSD: param.h,v 1.11 1998/08/30 22:05:35 millert Exp $ */
239300Sfenner
317680Spst/*-
417680Spst * Copyright (c) 1988 University of Utah.
517680Spst * Copyright (c) 1992, 1993
617680Spst *	The Regents of the University of California.  All rights reserved.
717680Spst *
817680Spst * This code is derived from software contributed to Berkeley by
917680Spst * the Systems Programming Group of the University of Utah Computer
1017680Spst * Science Department and Ralph Campbell.
1117680Spst *
1217680Spst * Redistribution and use in source and binary forms, with or without
1317680Spst * modification, are permitted provided that the following conditions
1417680Spst * are met:
1517680Spst * 1. Redistributions of source code must retain the above copyright
1617680Spst *    notice, this list of conditions and the following disclaimer.
1717680Spst * 2. Redistributions in binary form must reproduce the above copyright
1817680Spst *    notice, this list of conditions and the following disclaimer in the
1917680Spst *    documentation and/or other materials provided with the distribution.
2017680Spst * 4. Neither the name of the University nor the names of its contributors
2117680Spst *    may be used to endorse or promote products derived from this software
2217680Spst *    without specific prior written permission.
2326183Sfenner *
2439300Sfenner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2517680Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2617680Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2717680Spst * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2817680Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2917680Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3017680Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3117680Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3217680Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3317680Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3421262Swollman * SUCH DAMAGE.
3517680Spst *
3617680Spst *	from: Utah Hdr: machparam.h 1.11 89/08/14
3717680Spst *	from: @(#)param.h	8.1 (Berkeley) 6/10/93
3817680Spst *	JNPR: param.h,v 1.6.2.1 2007/09/10 07:49:36 girish
3917680Spst * $FreeBSD: head/sys/mips/include/param.h 233644 2012-03-29 02:54:35Z jmallett $
4017680Spst */
4117680Spst
4226183Sfenner#ifndef _MIPS_INCLUDE_PARAM_H_
4317680Spst#define	_MIPS_INCLUDE_PARAM_H_
4417680Spst
4517680Spst#include <machine/_align.h>
4617680Spst
4717680Spst#include <sys/cdefs.h>
4818976Sdfr#ifdef _KERNEL
4917680Spst#ifndef _LOCORE
5018976Sdfr#include <machine/cpu.h>
5117680Spst#endif
5217680Spst#endif
5318976Sdfr
5417680Spst#define __PCI_REROUTE_INTERRUPT
5518976Sdfr
5618976Sdfr#ifndef MACHINE
5718976Sdfr#define	MACHINE		"mips"
5818976Sdfr#endif
5917680Spst#ifndef MACHINE_ARCH
6026183Sfenner#if _BYTE_ORDER == _BIG_ENDIAN
6126183Sfenner#ifdef __mips_n64
6218976Sdfr#define	MACHINE_ARCH	"mips64"
6318976Sdfr#ifndef	MACHINE_ARCH32
6418976Sdfr#define	MACHINE_ARCH32	"mips"
6518976Sdfr#endif
6618976Sdfr#elif defined(__mips_n32)
6718976Sdfr#define	MACHINE_ARCH	"mipsn32"
6818976Sdfr#else
6918976Sdfr#define	MACHINE_ARCH	"mips"
7018976Sdfr#endif
7118976Sdfr#else
7218976Sdfr#ifdef __mips_n64
7318976Sdfr#define	MACHINE_ARCH	"mips64el"
7418976Sdfr#ifndef	MACHINE_ARCH32
7518976Sdfr#define	MACHINE_ARCH32	"mipsel"
7618976Sdfr#endif
7718976Sdfr#elif defined(__mips_n32)
7818976Sdfr#define	MACHINE_ARCH	"mipsn32el"
7918976Sdfr#else
8018976Sdfr#define	MACHINE_ARCH	"mipsel"
8118976Sdfr#endif
8218976Sdfr#endif
8318976Sdfr#endif
8418976Sdfr
8518976Sdfr/*
8618976Sdfr * OBJFORMAT_NAMES is a comma-separated list of the object formats
8718976Sdfr * that are supported on the architecture.
8818976Sdfr */
8918976Sdfr#define	OBJFORMAT_NAMES		"elf"
9018976Sdfr#define	OBJFORMAT_DEFAULT	"elf"
9118976Sdfr
9218976Sdfr#define	MID_MACHINE	0	/* None but has to be defined */
9318976Sdfr
9418976Sdfr#ifdef SMP
9518976Sdfr#define	MAXSMPCPU	32
9618976Sdfr#ifndef MAXCPU
9718976Sdfr#define	MAXCPU		MAXSMPCPU
9818976Sdfr#endif
9918976Sdfr#else
10018976Sdfr#define	MAXSMPCPU	1
10118976Sdfr#define	MAXCPU		1
10218976Sdfr#endif
10318976Sdfr
10418976Sdfr/*
10518976Sdfr * Round p (pointer or byte index) up to a correctly-aligned value for all
10618976Sdfr * data types (int, long, ...).	  The result is u_int and must be cast to
10718976Sdfr * any desired pointer type.
10818976Sdfr */
10918976Sdfr
11018976Sdfr#define	ALIGNBYTES	_ALIGNBYTES
11118976Sdfr#define	ALIGN(p)	_ALIGN(p)
11218976Sdfr/*
11318976Sdfr * ALIGNED_POINTER is a boolean macro that checks whether an address
11418976Sdfr * is valid to fetch data elements of type t from on this architecture.
11518976Sdfr * This does not reflect the optimal alignment, just the possibility
11618976Sdfr * (within reasonable limits).
11718976Sdfr */
11818976Sdfr#define	ALIGNED_POINTER(p, t)	((((unsigned long)(p)) & (sizeof (t) - 1)) == 0)
11918976Sdfr
12018976Sdfr/*
12118976Sdfr * CACHE_LINE_SIZE is the compile-time maximum cache line size for an
12218976Sdfr * architecture.  It should be used with appropriate caution.
12318976Sdfr */
12418976Sdfr#define	CACHE_LINE_SHIFT	6
12518976Sdfr#define	CACHE_LINE_SIZE		(1 << CACHE_LINE_SHIFT)
12618976Sdfr
12718976Sdfr#define	PAGE_SHIFT		12		/* LOG2(PAGE_SIZE) */
12818976Sdfr#define	PAGE_SIZE		(1<<PAGE_SHIFT) /* bytes/page */
12918976Sdfr#define	PAGE_MASK		(PAGE_SIZE-1)
13018976Sdfr
13118976Sdfr#define	NPTEPG			(PAGE_SIZE/(sizeof (pt_entry_t)))
13218976Sdfr#define	NPDEPG			(PAGE_SIZE/(sizeof (pd_entry_t)))
13318976Sdfr
13418976Sdfr#if defined(__mips_n32) || defined(__mips_n64) /*  PHYSADDR_64_BIT */
13518976Sdfr#define	NPTEPGSHIFT		9               /* LOG2(NPTEPG) */
13618976Sdfr#else
13718976Sdfr#define	NPTEPGSHIFT		10               /* LOG2(NPTEPG) */
13818976Sdfr#endif
13918976Sdfr
14018976Sdfr#ifdef __mips_n64
14118976Sdfr#define	NPDEPGSHIFT		9               /* LOG2(NPTEPG) */
14218976Sdfr#define	SEGSHIFT		(PAGE_SHIFT + NPTEPGSHIFT + NPDEPGSHIFT)
14318976Sdfr#define	NBSEG			(1ul << SEGSHIFT)
14418976Sdfr#define	PDRSHIFT		(PAGE_SHIFT + NPTEPGSHIFT)
14518976Sdfr#define	PDRMASK			((1 << PDRSHIFT) - 1)
14618976Sdfr#else
14718976Sdfr#define	NPDEPGSHIFT		10               /* LOG2(NPTEPG) */
14818976Sdfr#define	SEGSHIFT		(PAGE_SHIFT + NPTEPGSHIFT)
14918976Sdfr#define	NBSEG			(1 << SEGSHIFT)	/* bytes/segment */
15018976Sdfr#define	PDRSHIFT		SEGSHIFT	/* alias for SEG in 32 bit */
15118976Sdfr#define	PDRMASK			((1 << PDRSHIFT) - 1)
15218976Sdfr#endif
15318976Sdfr#define	NBPDR			(1 << PDRSHIFT)	/* bytes/pagedir */
15418976Sdfr#define	SEGMASK			(NBSEG - 1)	/* byte offset into segment */
15518976Sdfr
15618976Sdfr#define	MAXPAGESIZES		1		/* max supported pagesizes */
15718976Sdfr
15818976Sdfr#define	MAXDUMPPGS		1		/* xxx: why is this only one? */
15918976Sdfr
16018976Sdfr/*
16118976Sdfr * The kernel stack needs to be aligned on a (PAGE_SIZE * 2) boundary.
16218976Sdfr */
16318976Sdfr#define	KSTACK_PAGES		2	/* kernel stack */
16418976Sdfr#define	KSTACK_GUARD_PAGES	2	/* pages of kstack guard; 0 disables */
16518976Sdfr
16626183Sfenner#define	UPAGES			2
16718976Sdfr
16818976Sdfr/* pages ("clicks") (4096 bytes) to disk blocks */
16926183Sfenner#define	ctod(x)			((x) << (PAGE_SHIFT - DEV_BSHIFT))
17018976Sdfr#define	dtoc(x)			((x) >> (PAGE_SHIFT - DEV_BSHIFT))
17118976Sdfr
17218976Sdfr/*
17318976Sdfr * Map a ``block device block'' to a file system block.
17426183Sfenner * This should be device dependent, and should use the bsize
17518976Sdfr * field from the disk label.
17618976Sdfr * For now though just use DEV_BSIZE.
17726183Sfenner */
17818976Sdfr#define	bdbtofsb(bn)		((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
17918976Sdfr
18018976Sdfr/*
18118976Sdfr * Mach derived conversion macros
18226183Sfenner */
18318976Sdfr#define	round_page(x)		(((x) + PAGE_MASK) & ~PAGE_MASK)
18418976Sdfr#define	trunc_page(x)		((x) & ~PAGE_MASK)
18526183Sfenner
18618976Sdfr#define	atop(x)			((x) >> PAGE_SHIFT)
18718976Sdfr#define	ptoa(x)			((x) << PAGE_SHIFT)
18818976Sdfr
18918976Sdfr#define	pgtok(x)		((x) * (PAGE_SIZE / 1024))
19026183Sfenner
19118976Sdfr#endif /* !_MIPS_INCLUDE_PARAM_H_ */
19218976Sdfr