bat.h revision 263687
133965Sjdp/*-
2218822Sdim * Copyright (c) 1999 The NetBSD Foundation, Inc.
3218822Sdim * All rights reserved.
433965Sjdp *
5130561Sobrien * This code is derived from software contributed to The NetBSD Foundation
6130561Sobrien * by Jason R. Thorpe.
7130561Sobrien *
8130561Sobrien * Redistribution and use in source and binary forms, with or without
933965Sjdp * modification, are permitted provided that the following conditions
10130561Sobrien * are met:
11130561Sobrien * 1. Redistributions of source code must retain the above copyright
12130561Sobrien *    notice, this list of conditions and the following disclaimer.
13130561Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1433965Sjdp *    notice, this list of conditions and the following disclaimer in the
15130561Sobrien *    documentation and/or other materials provided with the distribution.
16130561Sobrien *
17218822Sdim * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1833965Sjdp * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19218822Sdim * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20218822Sdim * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21130561Sobrien * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22130561Sobrien * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23130561Sobrien * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24130561Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25130561Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26130561Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27130561Sobrien * POSSIBILITY OF SUCH DAMAGE.
28130561Sobrien */
29130561Sobrien
30130561Sobrien/*-
31130561Sobrien * Copyright (C) 1995, 1996 Wolfgang Solfrank.
32130561Sobrien * Copyright (C) 1995, 1996 TooLs GmbH.
33130561Sobrien * All rights reserved.
34130561Sobrien *
35130561Sobrien * Redistribution and use in source and binary forms, with or without
36130561Sobrien * modification, are permitted provided that the following conditions
37130561Sobrien * are met:
38130561Sobrien * 1. Redistributions of source code must retain the above copyright
39130561Sobrien *    notice, this list of conditions and the following disclaimer.
40130561Sobrien * 2. Redistributions in binary form must reproduce the above copyright
41130561Sobrien *    notice, this list of conditions and the following disclaimer in the
42130561Sobrien *    documentation and/or other materials provided with the distribution.
43130561Sobrien * 3. All advertising materials mentioning features or use of this software
44130561Sobrien *    must display the following acknowledgement:
45130561Sobrien *	This product includes software developed by TooLs GmbH.
46130561Sobrien * 4. The name of TooLs GmbH may not be used to endorse or promote products
47130561Sobrien *    derived from this software without specific prior written permission.
48130561Sobrien *
49130561Sobrien * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
50130561Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51130561Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52130561Sobrien * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53130561Sobrien * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
54130561Sobrien * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
55130561Sobrien * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
56130561Sobrien * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
57130561Sobrien * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
58130561Sobrien * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59130561Sobrien *
60130561Sobrien *	$NetBSD: bat.h,v 1.2 1999/12/18 01:36:06 thorpej Exp $
61130561Sobrien * $FreeBSD: stable/10/sys/powerpc/include/bat.h 263687 2014-03-24 13:48:04Z emaste $
62130561Sobrien */
63130561Sobrien
64130561Sobrien#ifndef	_MACHINE_BAT_H_
65130561Sobrien#define	_MACHINE_BAT_H_
66130561Sobrien
67130561Sobrien#ifndef LOCORE
68130561Sobrienstruct bat {
69130561Sobrien	u_int32_t batu;
70130561Sobrien	u_int32_t batl;
71130561Sobrien};
72130561Sobrien#endif
73130561Sobrien
74130561Sobrien/* Lower BAT bits (all but PowerPC 601): */
75130561Sobrien#define	BAT_PBS		0xfffe0000	/* physical block start */
76130561Sobrien#define	BAT_W		0x00000040	/* 1 = write-through, 0 = write-back */
77218822Sdim#define	BAT_I		0x00000020	/* cache inhibit */
78218822Sdim#define	BAT_M		0x00000010	/* memory coherency enable */
79218822Sdim#define	BAT_G		0x00000008	/* guarded region */
80218822Sdim
81218822Sdim#define	BAT_PP_NONE	0x00000000	/* no access permission */
82218822Sdim#define	BAT_PP_RO_S	0x00000001	/* read-only (soft) */
83218822Sdim#define	BAT_PP_RW	0x00000002	/* read/write */
84218822Sdim#define	BAT_PP_RO	0x00000003	/* read-only */
85218822Sdim
86218822Sdim/* Upper BAT bits (all but PowerPC 601): */
87218822Sdim#define	BAT_EBS		0xfffe0000	/* effective block start */
88218822Sdim#define	BAT_BL		0x00001ffc	/* block length */
89218822Sdim#define	BAT_Vs		0x00000002	/* valid in supervisor mode */
90218822Sdim#define	BAT_Vu		0x00000001	/* valid in user mode */
91218822Sdim
92218822Sdim#define	BAT_V		(BAT_Vs|BAT_Vu)
93130561Sobrien
94130561Sobrien/* Block Length encoding (all but PowerPC 601): */
9533965Sjdp#define	BAT_BL_128K	0x00000000
96130561Sobrien#define	BAT_BL_256K	0x00000004
97130561Sobrien#define	BAT_BL_512K	0x0000000c
98130561Sobrien#define	BAT_BL_1M	0x0000001c
99130561Sobrien#define	BAT_BL_2M	0x0000003c
100130561Sobrien#define	BAT_BL_4M	0x0000007c
101130561Sobrien#define	BAT_BL_8M	0x000000fc
102130561Sobrien#define	BAT_BL_16M	0x000001fc
103130561Sobrien#define	BAT_BL_32M	0x000003fc
104130561Sobrien#define	BAT_BL_64M	0x000007fc
105130561Sobrien#define	BAT_BL_128M	0x00000ffc
106130561Sobrien#define	BAT_BL_256M	0x00001ffc
107130561Sobrien
108130561Sobrien#define	BATU(va, len, v)						\
109130561Sobrien	(((va) & BAT_EBS) | ((len) & BAT_BL) | ((v) & BAT_V))
110130561Sobrien
111130561Sobrien#define	BATL(pa, wimg, pp)						\
112130561Sobrien	(((pa) & BAT_PBS) | (wimg) | (pp))
113130561Sobrien
114130561Sobrien
115130561Sobrien/* Lower BAT bits (PowerPC 601): */
116130561Sobrien#define	BAT601_PBN	0xfffe0000	/* physical block number */
117130561Sobrien#define	BAT601_V	0x00000040	/* valid */
118130561Sobrien#define	BAT601_BSM	0x0000003f	/* block size mask */
119130561Sobrien
120130561Sobrien/* Upper BAT bits (PowerPC 601): */
121130561Sobrien#define	BAT601_BLPI	0xfffe0000	/* block logical page index */
122130561Sobrien#define	BAT601_W	0x00000040	/* 1 = write-through, 0 = write-back */
123130561Sobrien#define	BAT601_I	0x00000020	/* cache inhibit */
124130561Sobrien#define	BAT601_M	0x00000010	/* memory coherency enable */
125130561Sobrien#define	BAT601_Ks	0x00000008	/* key-supervisor */
126130561Sobrien#define	BAT601_Ku	0x00000004	/* key-user */
127218822Sdim
128218822Sdim/*
129218822Sdim * Permission bits on the PowerPC 601 are modified by the appropriate
130218822Sdim * Key bit:
131218822Sdim *
132130561Sobrien *	Key	PP	Access
133130561Sobrien *	0	NONE	read/write
134130561Sobrien *	0	RO_S	read/write
135130561Sobrien *	0	RW	read/write
136130561Sobrien *	0	RO	read-only
137130561Sobrien *
138130561Sobrien *	1	NONE	none
139130561Sobrien *	1	RO_S	read-only
140130561Sobrien *	1	RW	read/write
141130561Sobrien *	1	RO	read-only
142130561Sobrien */
143130561Sobrien#define	BAT601_PP_NONE	0x00000000	/* no access permission */
144130561Sobrien#define	BAT601_PP_RO_S	0x00000001	/* read-only (soft) */
145130561Sobrien#define	BAT601_PP_RW	0x00000002	/* read/write */
146130561Sobrien#define	BAT601_PP_RO	0x00000003	/* read-only */
147130561Sobrien
148130561Sobrien/* Block Size Mask encoding (PowerPC 601): */
149130561Sobrien#define	BAT601_BSM_128K	0x00000000
150130561Sobrien#define	BAT601_BSM_256K	0x00000001
151130561Sobrien#define	BAT601_BSM_512K	0x00000003
152130561Sobrien#define	BAT601_BSM_1M	0x00000007
153130561Sobrien#define	BAT601_BSM_2M	0x0000000f
154130561Sobrien#define	BAT601_BSM_4M	0x0000001f
155130561Sobrien#define	BAT601_BSM_8M	0x0000003f
156130561Sobrien
157130561Sobrien#define	BATU601(va, wim, key, pp)					\
158130561Sobrien	(((va) & BAT601_BLPI) | (wim) | (key) | (pp))
159130561Sobrien
160130561Sobrien#define	BATL601(pa, size, v)						\
161130561Sobrien	(((pa) & BAT601_PBN) | (v) | (size))
162130561Sobrien
163130561Sobrien#if defined(_KERNEL) && !defined(LOCORE)
164130561Sobrienextern struct bat battable[16];
165130561Sobrien#endif
166130561Sobrien
167130561Sobrien#endif	/* _MACHINE_BAT_H_ */
168130561Sobrien