177957Sbenno/*-
277957Sbenno * Copyright (c) 1999 The NetBSD Foundation, Inc.
377957Sbenno * All rights reserved.
477957Sbenno *
577957Sbenno * This code is derived from software contributed to The NetBSD Foundation
677957Sbenno * by Jason R. Thorpe.
777957Sbenno *
877957Sbenno * Redistribution and use in source and binary forms, with or without
977957Sbenno * modification, are permitted provided that the following conditions
1077957Sbenno * are met:
1177957Sbenno * 1. Redistributions of source code must retain the above copyright
1277957Sbenno *    notice, this list of conditions and the following disclaimer.
1377957Sbenno * 2. Redistributions in binary form must reproduce the above copyright
1477957Sbenno *    notice, this list of conditions and the following disclaimer in the
1577957Sbenno *    documentation and/or other materials provided with the distribution.
1677957Sbenno *
1777957Sbenno * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1877957Sbenno * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1977957Sbenno * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2077957Sbenno * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2177957Sbenno * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2277957Sbenno * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2377957Sbenno * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2477957Sbenno * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2577957Sbenno * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2677957Sbenno * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2777957Sbenno * POSSIBILITY OF SUCH DAMAGE.
2877957Sbenno */
2977957Sbenno
30139825Simp/*-
3177957Sbenno * Copyright (C) 1995, 1996 Wolfgang Solfrank.
3277957Sbenno * Copyright (C) 1995, 1996 TooLs GmbH.
3377957Sbenno * All rights reserved.
3477957Sbenno *
3577957Sbenno * Redistribution and use in source and binary forms, with or without
3677957Sbenno * modification, are permitted provided that the following conditions
3777957Sbenno * are met:
3877957Sbenno * 1. Redistributions of source code must retain the above copyright
3977957Sbenno *    notice, this list of conditions and the following disclaimer.
4077957Sbenno * 2. Redistributions in binary form must reproduce the above copyright
4177957Sbenno *    notice, this list of conditions and the following disclaimer in the
4277957Sbenno *    documentation and/or other materials provided with the distribution.
4377957Sbenno * 3. All advertising materials mentioning features or use of this software
4477957Sbenno *    must display the following acknowledgement:
4577957Sbenno *	This product includes software developed by TooLs GmbH.
4677957Sbenno * 4. The name of TooLs GmbH may not be used to endorse or promote products
4777957Sbenno *    derived from this software without specific prior written permission.
4877957Sbenno *
4977957Sbenno * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
5077957Sbenno * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5177957Sbenno * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5277957Sbenno * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5377957Sbenno * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
5477957Sbenno * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
5577957Sbenno * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
5677957Sbenno * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5777957Sbenno * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5877957Sbenno * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5977957Sbenno *
6077957Sbenno *	$NetBSD: bat.h,v 1.2 1999/12/18 01:36:06 thorpej Exp $
6177957Sbenno * $FreeBSD$
6277957Sbenno */
6377957Sbenno
6477957Sbenno#ifndef	_MACHINE_BAT_H_
6577957Sbenno#define	_MACHINE_BAT_H_
6677957Sbenno
6777957Sbennostruct bat {
6877957Sbenno	u_int32_t batu;
6977957Sbenno	u_int32_t batl;
7077957Sbenno};
7177957Sbenno
7277957Sbenno/* Lower BAT bits (all but PowerPC 601): */
7377957Sbenno#define	BAT_PBS		0xfffe0000	/* physical block start */
7477957Sbenno#define	BAT_W		0x00000040	/* 1 = write-through, 0 = write-back */
7577957Sbenno#define	BAT_I		0x00000020	/* cache inhibit */
7677957Sbenno#define	BAT_M		0x00000010	/* memory coherency enable */
7777957Sbenno#define	BAT_G		0x00000008	/* guarded region */
7877957Sbenno
7977957Sbenno#define	BAT_PP_NONE	0x00000000	/* no access permission */
8077957Sbenno#define	BAT_PP_RO_S	0x00000001	/* read-only (soft) */
8177957Sbenno#define	BAT_PP_RW	0x00000002	/* read/write */
8277957Sbenno#define	BAT_PP_RO	0x00000003	/* read-only */
8377957Sbenno
8477957Sbenno/* Upper BAT bits (all but PowerPC 601): */
8577957Sbenno#define	BAT_EBS		0xfffe0000	/* effective block start */
8677957Sbenno#define	BAT_BL		0x00001ffc	/* block length */
8777957Sbenno#define	BAT_Vs		0x00000002	/* valid in supervisor mode */
8877957Sbenno#define	BAT_Vu		0x00000001	/* valid in user mode */
8977957Sbenno
9077957Sbenno#define	BAT_V		(BAT_Vs|BAT_Vu)
9177957Sbenno
9277957Sbenno/* Block Length encoding (all but PowerPC 601): */
9377957Sbenno#define	BAT_BL_128K	0x00000000
9477957Sbenno#define	BAT_BL_256K	0x00000004
9577957Sbenno#define	BAT_BL_512K	0x0000000c
9677957Sbenno#define	BAT_BL_1M	0x0000001c
9777957Sbenno#define	BAT_BL_2M	0x0000003c
9877957Sbenno#define	BAT_BL_4M	0x0000007c
9977957Sbenno#define	BAT_BL_8M	0x000000fc
10077957Sbenno#define	BAT_BL_16M	0x000001fc
10177957Sbenno#define	BAT_BL_32M	0x000003fc
10277957Sbenno#define	BAT_BL_64M	0x000007fc
10377957Sbenno#define	BAT_BL_128M	0x00000ffc
10477957Sbenno#define	BAT_BL_256M	0x00001ffc
10577957Sbenno
10677957Sbenno#define	BATU(va, len, v)						\
10777957Sbenno	(((va) & BAT_EBS) | ((len) & BAT_BL) | ((v) & BAT_V))
10877957Sbenno
10977957Sbenno#define	BATL(pa, wimg, pp)						\
11077957Sbenno	(((pa) & BAT_PBS) | (wimg) | (pp))
11177957Sbenno
11277957Sbenno
11377957Sbenno/* Lower BAT bits (PowerPC 601): */
11477957Sbenno#define	BAT601_PBN	0xfffe0000	/* physical block number */
11577957Sbenno#define	BAT601_V	0x00000040	/* valid */
11677957Sbenno#define	BAT601_BSM	0x0000003f	/* block size mask */
11777957Sbenno
11877957Sbenno/* Upper BAT bits (PowerPC 601): */
11977957Sbenno#define	BAT601_BLPI	0xfffe0000	/* block logical page index */
12077957Sbenno#define	BAT601_W	0x00000040	/* 1 = write-through, 0 = write-back */
12177957Sbenno#define	BAT601_I	0x00000020	/* cache inhibit */
12277957Sbenno#define	BAT601_M	0x00000010	/* memory coherency enable */
12377957Sbenno#define	BAT601_Ks	0x00000008	/* key-supervisor */
12477957Sbenno#define	BAT601_Ku	0x00000004	/* key-user */
12577957Sbenno
12677957Sbenno/*
12777957Sbenno * Permission bits on the PowerPC 601 are modified by the appropriate
12877957Sbenno * Key bit:
12977957Sbenno *
13077957Sbenno *	Key	PP	Access
13177957Sbenno *	0	NONE	read/write
13277957Sbenno *	0	RO_S	read/write
13377957Sbenno *	0	RW	read/write
13477957Sbenno *	0	RO	read-only
13577957Sbenno *
13677957Sbenno *	1	NONE	none
13777957Sbenno *	1	RO_S	read-only
13877957Sbenno *	1	RW	read/write
13977957Sbenno *	1	RO	read-only
14077957Sbenno */
14177957Sbenno#define	BAT601_PP_NONE	0x00000000	/* no access permission */
14277957Sbenno#define	BAT601_PP_RO_S	0x00000001	/* read-only (soft) */
14377957Sbenno#define	BAT601_PP_RW	0x00000002	/* read/write */
14477957Sbenno#define	BAT601_PP_RO	0x00000003	/* read-only */
14577957Sbenno
14677957Sbenno/* Block Size Mask encoding (PowerPC 601): */
14777957Sbenno#define	BAT601_BSM_128K	0x00000000
14877957Sbenno#define	BAT601_BSM_256K	0x00000001
14977957Sbenno#define	BAT601_BSM_512K	0x00000003
15077957Sbenno#define	BAT601_BSM_1M	0x00000007
15177957Sbenno#define	BAT601_BSM_2M	0x0000000f
15277957Sbenno#define	BAT601_BSM_4M	0x0000001f
15377957Sbenno#define	BAT601_BSM_8M	0x0000003f
15477957Sbenno
15577957Sbenno#define	BATU601(va, wim, key, pp)					\
15677957Sbenno	(((va) & BAT601_BLPI) | (wim) | (key) | (pp))
15777957Sbenno
15877957Sbenno#define	BATL601(pa, size, v)						\
15977957Sbenno	(((pa) & BAT601_PBN) | (v) | (size))
16077957Sbenno
16177957Sbenno#ifdef _KERNEL
16277957Sbennoextern struct bat battable[16];
16377957Sbenno#endif
16477957Sbenno
16577957Sbenno#endif	/* _MACHINE_BAT_H_ */
166