xref: /netbsd-src/sys/arch/powerpc/include/ibm4xx/tlb.h (revision 331fceca56ec91e29e44e735b0273a6e51cd5be1)
1*331fcecaSrin /*	$NetBSD: tlb.h,v 1.7 2021/03/30 03:15:53 rin Exp $	*/
218b2f7e6Ssimonb 
318b2f7e6Ssimonb /*
418b2f7e6Ssimonb  * Copyright 2001 Wasabi Systems, Inc.
518b2f7e6Ssimonb  * All rights reserved.
618b2f7e6Ssimonb  *
718b2f7e6Ssimonb  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
818b2f7e6Ssimonb  *
918b2f7e6Ssimonb  * Redistribution and use in source and binary forms, with or without
1018b2f7e6Ssimonb  * modification, are permitted provided that the following conditions
1118b2f7e6Ssimonb  * are met:
1218b2f7e6Ssimonb  * 1. Redistributions of source code must retain the above copyright
1318b2f7e6Ssimonb  *    notice, this list of conditions and the following disclaimer.
1418b2f7e6Ssimonb  * 2. Redistributions in binary form must reproduce the above copyright
1518b2f7e6Ssimonb  *    notice, this list of conditions and the following disclaimer in the
1618b2f7e6Ssimonb  *    documentation and/or other materials provided with the distribution.
1718b2f7e6Ssimonb  * 3. All advertising materials mentioning features or use of this software
1818b2f7e6Ssimonb  *    must display the following acknowledgement:
1918b2f7e6Ssimonb  *      This product includes software developed for the NetBSD Project by
2018b2f7e6Ssimonb  *      Wasabi Systems, Inc.
2118b2f7e6Ssimonb  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
2218b2f7e6Ssimonb  *    or promote products derived from this software without specific prior
2318b2f7e6Ssimonb  *    written permission.
2418b2f7e6Ssimonb  *
2518b2f7e6Ssimonb  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
2618b2f7e6Ssimonb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2718b2f7e6Ssimonb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2818b2f7e6Ssimonb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
2918b2f7e6Ssimonb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3018b2f7e6Ssimonb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3118b2f7e6Ssimonb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3218b2f7e6Ssimonb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3318b2f7e6Ssimonb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3418b2f7e6Ssimonb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3518b2f7e6Ssimonb  * POSSIBILITY OF SUCH DAMAGE.
3618b2f7e6Ssimonb  */
3718b2f7e6Ssimonb 
3818b2f7e6Ssimonb #ifndef _IBM4XX_TLB_H_
3918b2f7e6Ssimonb #define _IBM4XX_TLB_H_
4018b2f7e6Ssimonb 
4118b2f7e6Ssimonb #define NTLB	64
4218b2f7e6Ssimonb 
4318b2f7e6Ssimonb /* TLBHI entries */
4418b2f7e6Ssimonb #define TLB_EPN_MASK	0xfffff000 /* It's 0xfffffc00, but as we use 4K pages we don't need two lower bits */
4518b2f7e6Ssimonb #define TLB_EPN_SHFT	12
4618b2f7e6Ssimonb #define TLB_SIZE_MASK	0x00000380
4718b2f7e6Ssimonb #define TLB_SIZE_SHFT	7
4818b2f7e6Ssimonb #define TLB_VALID	0x00000040
4918b2f7e6Ssimonb #define TLB_ENDIAN	0x00000020
5018b2f7e6Ssimonb #define TLB_U0		0x00000010
5118b2f7e6Ssimonb 
5218b2f7e6Ssimonb #define TLB_SIZE_1K	0
5318b2f7e6Ssimonb #define TLB_SIZE_4K	1
5418b2f7e6Ssimonb #define TLB_SIZE_16K	2
5518b2f7e6Ssimonb #define TLB_SIZE_64K	3
5618b2f7e6Ssimonb #define TLB_SIZE_256K	4
5718b2f7e6Ssimonb #define TLB_SIZE_1M	5
5818b2f7e6Ssimonb #define TLB_SIZE_4M	6
5918b2f7e6Ssimonb #define TLB_SIZE_16M	7
6018b2f7e6Ssimonb 
6118b2f7e6Ssimonb #define	TLB_PG_1K	(TLB_SIZE_1K << TLB_SIZE_SHFT)
6218b2f7e6Ssimonb #define	TLB_PG_4K	(TLB_SIZE_4K << TLB_SIZE_SHFT)
6318b2f7e6Ssimonb #define	TLB_PG_16K	(TLB_SIZE_16K << TLB_SIZE_SHFT)
6418b2f7e6Ssimonb #define	TLB_PG_64K	(TLB_SIZE_64K << TLB_SIZE_SHFT)
6518b2f7e6Ssimonb #define	TLB_PG_256K	(TLB_SIZE_256K << TLB_SIZE_SHFT)
6618b2f7e6Ssimonb #define	TLB_PG_1M	(TLB_SIZE_1M << TLB_SIZE_SHFT)
6718b2f7e6Ssimonb #define	TLB_PG_4M	(TLB_SIZE_4M << TLB_SIZE_SHFT)
6818b2f7e6Ssimonb #define	TLB_PG_16M	(TLB_SIZE_16M << TLB_SIZE_SHFT)
6918b2f7e6Ssimonb 
7018b2f7e6Ssimonb /* TLBLO entries */
7118b2f7e6Ssimonb #define TLB_RPN_MASK	0xfffffc00	/* Real Page Number mask */
7218b2f7e6Ssimonb #define TLB_EX		0x00000200	/* EXecute enable */
7318b2f7e6Ssimonb #define TLB_WR		0x00000100	/* WRite enable */
7418b2f7e6Ssimonb #define TLB_ZSEL_MASK	0x000000f0	/* Zone SELect mask */
7518b2f7e6Ssimonb #define TLB_ZSEL_SHFT	4
7618b2f7e6Ssimonb #define TLB_W		0x00000008	/* Write-through */
7718b2f7e6Ssimonb #define TLB_I		0x00000004	/* Inhibit caching */
7818b2f7e6Ssimonb #define TLB_M		0x00000002	/* Memory coherent */
7918b2f7e6Ssimonb #define TLB_G		0x00000001	/* Guarded */
8018b2f7e6Ssimonb 
8118b2f7e6Ssimonb #define TLB_ZONE(z)	(((z) << TLB_ZSEL_SHFT) & TLB_ZSEL_MASK)
8218b2f7e6Ssimonb 
8318b2f7e6Ssimonb /* We only need two zones for kernel and user-level processes */
8418b2f7e6Ssimonb #define TLB_SU_ZONE	0	/* Kernel-only access controlled permission bits in TLB */
8518b2f7e6Ssimonb #define TLB_U_ZONE	1	/* Access always controlled by permission bits in TLB entry */
8618b2f7e6Ssimonb 
8718b2f7e6Ssimonb #define TLB_HI(epn,size,flags)	(((epn)&TLB_EPN_MASK)|(((size)<<TLB_SIZE_SHFT)&TLB_SIZE_MASK)|(flags))
8818b2f7e6Ssimonb #define TLB_LO(rpn,zone,flags)	(((rpn)&TLB_RPN_MASK)|(((zone)<<TLB_ZSEL_SHFT)&TLB_ZSEL_MASK)|(flags))
8918b2f7e6Ssimonb 
9018b2f7e6Ssimonb #ifndef _LOCORE
9118b2f7e6Ssimonb 
9218b2f7e6Ssimonb typedef struct tlb_s {
9318b2f7e6Ssimonb 	u_int tlb_hi;
9418b2f7e6Ssimonb 	u_int tlb_lo;
9518b2f7e6Ssimonb } tlb_t;
9618b2f7e6Ssimonb 
9718b2f7e6Ssimonb struct	pmap;
9818b2f7e6Ssimonb 
9918b2f7e6Ssimonb void	ppc4xx_tlb_enter(int, vaddr_t, u_int);
10018b2f7e6Ssimonb void	ppc4xx_tlb_flush(vaddr_t, int);
10118b2f7e6Ssimonb void	ppc4xx_tlb_flush_all(void);
10218b2f7e6Ssimonb void	ppc4xx_tlb_init(void);
10318b2f7e6Ssimonb int	ppc4xx_tlb_new_pid(struct pmap *);
104ca97defaSfreza void	ppc4xx_tlb_reserve(paddr_t, vaddr_t, size_t, int);
105ca97defaSfreza void 	*ppc4xx_tlb_mapiodev(paddr_t, psize_t);
10618b2f7e6Ssimonb 
107*331fcecaSrin #ifndef ppc4xx_tlbflags
108*331fcecaSrin #define	ppc4xx_tlbflags(va, pa)	(0)
10918b2f7e6Ssimonb #endif
11018b2f7e6Ssimonb 
111*331fcecaSrin #endif /* !_LOCORE */
112*331fcecaSrin 
11318b2f7e6Ssimonb #define TLB_PID_INVALID 0xFFFF
11418b2f7e6Ssimonb 
11518b2f7e6Ssimonb #endif	/* _IBM4XX_TLB_H_ */
116