xref: /netbsd-src/sys/arch/powerpc/include/oea/bat.h (revision 36c20c467240dd31afd7de63c00b9022f47f0980)
1*36c20c46Srin /*	$NetBSD: bat.h,v 1.20 2020/07/06 10:31:23 rin Exp $	*/
22b0e97a5Smatt 
32b0e97a5Smatt /*-
42b0e97a5Smatt  * Copyright (c) 1999 The NetBSD Foundation, Inc.
52b0e97a5Smatt  * All rights reserved.
62b0e97a5Smatt  *
72b0e97a5Smatt  * This code is derived from software contributed to The NetBSD Foundation
82b0e97a5Smatt  * by Jason R. Thorpe.
92b0e97a5Smatt  *
102b0e97a5Smatt  * Redistribution and use in source and binary forms, with or without
112b0e97a5Smatt  * modification, are permitted provided that the following conditions
122b0e97a5Smatt  * are met:
132b0e97a5Smatt  * 1. Redistributions of source code must retain the above copyright
142b0e97a5Smatt  *    notice, this list of conditions and the following disclaimer.
152b0e97a5Smatt  * 2. Redistributions in binary form must reproduce the above copyright
162b0e97a5Smatt  *    notice, this list of conditions and the following disclaimer in the
172b0e97a5Smatt  *    documentation and/or other materials provided with the distribution.
182b0e97a5Smatt  *
192b0e97a5Smatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
202b0e97a5Smatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
212b0e97a5Smatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
222b0e97a5Smatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
232b0e97a5Smatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
242b0e97a5Smatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
252b0e97a5Smatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
262b0e97a5Smatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
272b0e97a5Smatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
282b0e97a5Smatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
292b0e97a5Smatt  * POSSIBILITY OF SUCH DAMAGE.
302b0e97a5Smatt  */
312b0e97a5Smatt 
322b0e97a5Smatt /*
332b0e97a5Smatt  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
342b0e97a5Smatt  * Copyright (C) 1995, 1996 TooLs GmbH.
352b0e97a5Smatt  * All rights reserved.
362b0e97a5Smatt  *
372b0e97a5Smatt  * Redistribution and use in source and binary forms, with or without
382b0e97a5Smatt  * modification, are permitted provided that the following conditions
392b0e97a5Smatt  * are met:
402b0e97a5Smatt  * 1. Redistributions of source code must retain the above copyright
412b0e97a5Smatt  *    notice, this list of conditions and the following disclaimer.
422b0e97a5Smatt  * 2. Redistributions in binary form must reproduce the above copyright
432b0e97a5Smatt  *    notice, this list of conditions and the following disclaimer in the
442b0e97a5Smatt  *    documentation and/or other materials provided with the distribution.
452b0e97a5Smatt  * 3. All advertising materials mentioning features or use of this software
462b0e97a5Smatt  *    must display the following acknowledgement:
472b0e97a5Smatt  *	This product includes software developed by TooLs GmbH.
482b0e97a5Smatt  * 4. The name of TooLs GmbH may not be used to endorse or promote products
492b0e97a5Smatt  *    derived from this software without specific prior written permission.
502b0e97a5Smatt  *
512b0e97a5Smatt  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
522b0e97a5Smatt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
532b0e97a5Smatt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
542b0e97a5Smatt  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
552b0e97a5Smatt  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
562b0e97a5Smatt  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
572b0e97a5Smatt  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
582b0e97a5Smatt  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
592b0e97a5Smatt  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
602b0e97a5Smatt  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
612b0e97a5Smatt  */
622b0e97a5Smatt 
632b0e97a5Smatt #ifndef	_POWERPC_OEA_BAT_H_
642b0e97a5Smatt #define	_POWERPC_OEA_BAT_H_
652b0e97a5Smatt 
660c9a82b2Snisimura #if defined(_KERNEL) && !defined(_LOCORE)
6716031f7dSrin 
68*36c20c46Srin #ifdef _KERNEL_OPT
69*36c20c46Srin #include "opt_ppcarch.h"
70*36c20c46Srin #endif
71*36c20c46Srin 
7279d5c05dSmatt #include <powerpc/psl.h>
7379d5c05dSmatt 
742b0e97a5Smatt struct bat {
753cdbb8ccSmatt 	register_t batu;
763cdbb8ccSmatt 	register_t batl;
77c496beb1Smrg } __aligned(8);
78d7fc76efSmatt #endif
792b0e97a5Smatt 
802b0e97a5Smatt /* Lower BAT bits (all but PowerPC 601): */
81cc7308ceSmatt #define	BAT_RPN		(~0x1ffff)	/* physical block start */
829b69be93Smatt #define	BAT_XPN		0x00000e00	/* eXtended physical page number (0-2) */
832b0e97a5Smatt #define	BAT_W		0x00000040	/* 1 = write-through, 0 = write-back */
842b0e97a5Smatt #define	BAT_I		0x00000020	/* cache inhibit */
852b0e97a5Smatt #define	BAT_M		0x00000010	/* memory coherency enable */
862b0e97a5Smatt #define	BAT_G		0x00000008	/* guarded region (not on 601) */
879b69be93Smatt #define	BAT_X		0x00000004	/* eXtended physical page number (3) */
882fb44af0Smatt #define	BAT_WIMG	0x00000078	/* WIMG mask */
899b69be93Smatt 
909b69be93Smatt /*
919b69be93Smatt  * BAT_XPN and BAT_X are only used when HID0[XAEN] == 1 and are used
929b69be93Smatt  * to generate the 4 MSB of physical address
939b69be93Smatt  */
942b0e97a5Smatt 
952b0e97a5Smatt #define	BAT_PP		0x00000003	/* PP mask */
962b0e97a5Smatt #define	BAT_PP_NONE	0x00000000	/* no access permission */
972b0e97a5Smatt #define	BAT_PP_RO_S	0x00000001	/* read-only (soft) */
982b0e97a5Smatt #define	BAT_PP_RW	0x00000002	/* read/write */
992b0e97a5Smatt #define	BAT_PP_RO	0x00000003	/* read-only */
1002b0e97a5Smatt 
1012b0e97a5Smatt /* Upper BAT bits (all but PowerPC 601): */
102cc7308ceSmatt #define	BAT_EPI		(~0x1ffffL)	/* effective block start */
1032b0e97a5Smatt #define	BAT_BL		0x00001ffc	/* block length */
1042b0e97a5Smatt #define	BAT_Vs		0x00000002	/* valid in supervisor mode */
1052b0e97a5Smatt #define	BAT_Vu		0x00000001	/* valid in user mode */
1062b0e97a5Smatt 
1079b69be93Smatt #define	BAT_XBL		0x0001e000	/* eXtended Block Length (*) */
1089b69be93Smatt #define	BAT_XBL_512M	0x00002000	/* XBL for 512MB */
1099b69be93Smatt #define	BAT_XBL_1G	0x00006000	/* XBL for 1GB */
1109b69be93Smatt #define	BAT_XBL_2G	0x0000e000	/* XBL for 2GB */
1119b69be93Smatt #define	BAT_XBL_4G	0x0001e000	/* XBL for 4GB */
1129b69be93Smatt 
1132b0e97a5Smatt #define	BAT_V		(BAT_Vs|BAT_Vu)
1142b0e97a5Smatt 
1152b0e97a5Smatt /* Block Length encoding (all but PowerPC 601): */
1162b0e97a5Smatt #define	BAT_BL_128K	0x00000000
1172b0e97a5Smatt #define	BAT_BL_256K	0x00000004
1182b0e97a5Smatt #define	BAT_BL_512K	0x0000000c
1192b0e97a5Smatt #define	BAT_BL_1M	0x0000001c
1202b0e97a5Smatt #define	BAT_BL_2M	0x0000003c
1212b0e97a5Smatt #define	BAT_BL_4M	0x0000007c
1222b0e97a5Smatt #define	BAT_BL_8M	0x000000fc
1232b0e97a5Smatt #define	BAT_BL_16M	0x000001fc
1242b0e97a5Smatt #define	BAT_BL_32M	0x000003fc
1252b0e97a5Smatt #define	BAT_BL_64M	0x000007fc
1262b0e97a5Smatt #define	BAT_BL_128M	0x00000ffc
1272b0e97a5Smatt #define	BAT_BL_256M	0x00001ffc
1282fb44af0Smatt /* Extended Block Lengths (7455+) */
1292fb44af0Smatt #define	BAT_BL_512M	0x00003ffc
1302fb44af0Smatt #define	BAT_BL_1G	0x00007ffc
1312fb44af0Smatt #define	BAT_BL_2G	0x0000fffc
1322fb44af0Smatt #define	BAT_BL_4G	0x0001fffc
1332b0e97a5Smatt 
134413fb4c3Smatt #define	BAT_BL_TO_SIZE(bl)	(((bl)+4) << 15)
135413fb4c3Smatt 
1362b0e97a5Smatt #define	BATU(va, len, v)						\
13769545c61Smatt 	(((va) & BAT_EPI) | ((len) & (BAT_BL|BAT_XBL)) | ((v) & BAT_V))
1382b0e97a5Smatt 
1392b0e97a5Smatt #define	BATL(pa, wimg, pp)						\
1403cdbb8ccSmatt 	(((pa) & BAT_RPN) | (wimg) | (pp))
1412b0e97a5Smatt 
1422b0e97a5Smatt #define BAT_VA_MATCH_P(batu,va) \
143a6d582edSmacallan   (((~(((batu)&(BAT_BL|BAT_XBL))<<15))&(va)&BAT_EPI)==((batu)&BAT_EPI))
1442b0e97a5Smatt 
145d7fc76efSmatt #define BAT_PA_MATCH_P(batu,batl,pa) \
146a6d582edSmacallan   (((~(((batu)&(BAT_BL|BAT_XBL))<<15))&(pa)&BAT_RPN)==((batl)&BAT_RPN))
147d7fc76efSmatt 
1482b0e97a5Smatt #define BAT_VALID_P(batu, msr) \
1492b0e97a5Smatt   (((msr)&PSL_PR)?(((batu)&BAT_Vu)==BAT_Vu):(((batu)&BAT_Vs)==BAT_Vs))
1502b0e97a5Smatt 
1512b0e97a5Smatt /* Lower BAT bits (PowerPC 601): */
1522b0e97a5Smatt #define	BAT601_PBN	0xfffe0000	/* physical block number */
1532b0e97a5Smatt #define	BAT601_V	0x00000040	/* valid */
1542b0e97a5Smatt #define	BAT601_BSM	0x0000003f	/* block size mask */
1552b0e97a5Smatt 
1562b0e97a5Smatt /* Upper BAT bits (PowerPC 601): */
1572b0e97a5Smatt #define	BAT601_BLPI	0xfffe0000	/* block logical page index */
1582b0e97a5Smatt #define	BAT601_W	0x00000040	/* 1 = write-through, 0 = write-back */
1592b0e97a5Smatt #define	BAT601_I	0x00000020	/* cache inhibit */
1602b0e97a5Smatt #define	BAT601_M	0x00000010	/* memory coherency enable */
1612b0e97a5Smatt #define	BAT601_Ks	0x00000008	/* key-supervisor */
1622b0e97a5Smatt #define	BAT601_Ku	0x00000004	/* key-user */
1632b0e97a5Smatt 
1642b0e97a5Smatt /*
1652b0e97a5Smatt  * Permission bits on the PowerPC 601 are modified by the appropriate
1662b0e97a5Smatt  * Key bit:
1672b0e97a5Smatt  *
1682b0e97a5Smatt  *	Key	PP	Access
1692b0e97a5Smatt  *	0	NONE	read/write
1702b0e97a5Smatt  *	0	RO_S	read/write
1712b0e97a5Smatt  *	0	RW	read/write
1722b0e97a5Smatt  *	0	RO	read-only
1732b0e97a5Smatt  *
1742b0e97a5Smatt  *	1	NONE	none
1752b0e97a5Smatt  *	1	RO_S	read-only
1762b0e97a5Smatt  *	1	RW	read/write
1772b0e97a5Smatt  *	1	RO	read-only
1782b0e97a5Smatt  */
1792b0e97a5Smatt #define	BAT601_PP	0x00000003
1802b0e97a5Smatt #define	BAT601_PP_NONE	0x00000000	/* no access permission */
1812b0e97a5Smatt #define	BAT601_PP_RO_S	0x00000001	/* read-only (soft) */
1822b0e97a5Smatt #define	BAT601_PP_RW	0x00000002	/* read/write */
1832b0e97a5Smatt #define	BAT601_PP_RO	0x00000003	/* read-only */
1842b0e97a5Smatt 
1852b0e97a5Smatt /* Block Size Mask encoding (PowerPC 601): */
1862b0e97a5Smatt #define	BAT601_BSM_128K	0x00000000
1872b0e97a5Smatt #define	BAT601_BSM_256K	0x00000001
1882b0e97a5Smatt #define	BAT601_BSM_512K	0x00000003
1892b0e97a5Smatt #define	BAT601_BSM_1M	0x00000007
1902b0e97a5Smatt #define	BAT601_BSM_2M	0x0000000f
1912b0e97a5Smatt #define	BAT601_BSM_4M	0x0000001f
1922b0e97a5Smatt #define	BAT601_BSM_8M	0x0000003f
1932b0e97a5Smatt 
1942b0e97a5Smatt #define	BATU601(va, wim, key, pp)					\
1952b0e97a5Smatt 	(((va) & BAT601_BLPI) | (wim) | (key) | (pp))
1962b0e97a5Smatt 
1972b0e97a5Smatt #define	BATL601(pa, size, v)						\
1982b0e97a5Smatt 	(((pa) & BAT601_PBN) | (v) | (size))
1992b0e97a5Smatt 
2002b0e97a5Smatt #define	BAT601_VA_MATCH_P(batu, batl, va)				\
2012b0e97a5Smatt 	(((~(((batl)&BAT601_BSM)<<17))&(va)&BAT601_BLPI)==((batu)&BAT601_BLPI))
2022b0e97a5Smatt 
2032b0e97a5Smatt #define	BAT601_VALID_P(batl) \
2042b0e97a5Smatt 	((batl) & BAT601_V)
2052b0e97a5Smatt 
206413fb4c3Smatt #define	BAT_VA2IDX(va)	((va) / (8*1024*1024))
207413fb4c3Smatt #define	BAT_IDX2VA(i)	((i) * (8*1024*1024))
2087aa9230dSmatt 
2090c9a82b2Snisimura #if defined(_KERNEL) && !defined(_LOCORE)
2102b0e97a5Smatt void oea_batinit(paddr_t, ...);
2112b0e97a5Smatt void oea_iobat_add(paddr_t, register_t);
2125d223c9cSmatt void oea_iobat_remove(paddr_t);
213265929b2Ssanjayl 
2144b513a99Sgarbled #if !defined (PPC_OEA64)
2152b0e97a5Smatt extern struct bat battable[];
216265929b2Ssanjayl #endif /* PPC_OEA */
2172b0e97a5Smatt #endif
2182b0e97a5Smatt 
2192b0e97a5Smatt #endif	/* _POWERPC_OEA_BAT_H_ */
220