xref: /freebsd/sys/powerpc/include/slb.h (revision 1cd30eb6dd61f24520d2dfc71856ac94c4f7b5ad)
1c3e289e1SNathan Whitehorn /*-
2c3e289e1SNathan Whitehorn  * Copyright (C) 2009 Nathan Whitehorn
3c3e289e1SNathan Whitehorn  * All rights reserved.
4c3e289e1SNathan Whitehorn  *
5c3e289e1SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
6c3e289e1SNathan Whitehorn  * modification, are permitted provided that the following conditions
7c3e289e1SNathan Whitehorn  * are met:
8c3e289e1SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
9c3e289e1SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
10c3e289e1SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
11c3e289e1SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
12c3e289e1SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
13c3e289e1SNathan Whitehorn  *
14c3e289e1SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15c3e289e1SNathan Whitehorn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16c3e289e1SNathan Whitehorn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17c3e289e1SNathan Whitehorn  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18c3e289e1SNathan Whitehorn  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19c3e289e1SNathan Whitehorn  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20c3e289e1SNathan Whitehorn  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21c3e289e1SNathan Whitehorn  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22c3e289e1SNathan Whitehorn  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23c3e289e1SNathan Whitehorn  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24c3e289e1SNathan Whitehorn  *
25c3e289e1SNathan Whitehorn  * $FreeBSD$
26c3e289e1SNathan Whitehorn  */
27c3e289e1SNathan Whitehorn 
28c3e289e1SNathan Whitehorn #ifndef _MACHINE_SLB_H_
29c3e289e1SNathan Whitehorn #define	_MACHINE_SLB_H_
30c3e289e1SNathan Whitehorn 
31c3e289e1SNathan Whitehorn /*
32c3e289e1SNathan Whitehorn  * Bit definitions for segment lookaside buffer entries.
33c3e289e1SNathan Whitehorn  *
34c3e289e1SNathan Whitehorn  * PowerPC Microprocessor Family: The Programming Environments for 64-bit
35c3e289e1SNathan Whitehorn  * Microprocessors, section 7.4.2.1
36c3e289e1SNathan Whitehorn  *
37c3e289e1SNathan Whitehorn  * Note that these bitmasks are relative to the values for one of the two
38c3e289e1SNathan Whitehorn  * values for slbmte, slbmfee, and slbmfev, not the internal SLB
39c3e289e1SNathan Whitehorn  * representation.
40c3e289e1SNathan Whitehorn  */
41c3e289e1SNathan Whitehorn 
42c3e289e1SNathan Whitehorn #define	SLBV_KS		0x0000000000000800UL /* Supervisor-state prot key */
43c3e289e1SNathan Whitehorn #define	SLBV_KP		0x0000000000000400UL /* User-state prot key */
44c3e289e1SNathan Whitehorn #define	SLBV_N		0x0000000000000200UL /* No-execute protection */
45c3e289e1SNathan Whitehorn #define	SLBV_L		0x0000000000000100UL /* Large page selector */
46c3e289e1SNathan Whitehorn #define	SLBV_CLASS	0x0000000000000080UL /* Class selector */
47c3e289e1SNathan Whitehorn #define	SLBV_VSID_MASK	0xfffffffffffff000UL /* Virtual segment ID mask */
48c3e289e1SNathan Whitehorn #define	SLBV_VSID_SHIFT	12
49c3e289e1SNathan Whitehorn 
50c3e289e1SNathan Whitehorn /*
513b4b3830SNathan Whitehorn  * Make a predictable 1:1 map from ESIDs to VSIDs for the kernel. Hash table
523b4b3830SNathan Whitehorn  * coverage is increased by swizzling the ESID and multiplying by a prime
533b4b3830SNathan Whitehorn  * number (0x13bb).
54c3e289e1SNathan Whitehorn  */
553b4b3830SNathan Whitehorn #define	KERNEL_VSID_BIT	0x0000001000000000UL /* Bit set in all kernel VSIDs */
563b4b3830SNathan Whitehorn #define KERNEL_VSID(esid) ((((((uint64_t)esid << 8) | ((uint64_t)esid >> 28)) \
573b4b3830SNathan Whitehorn 				* 0x13bbUL) & (KERNEL_VSID_BIT - 1)) | \
583b4b3830SNathan Whitehorn 				KERNEL_VSID_BIT)
59c3e289e1SNathan Whitehorn 
60c3e289e1SNathan Whitehorn #define	SLBE_VALID	0x0000000008000000UL /* SLB entry valid */
61c3e289e1SNathan Whitehorn #define	SLBE_INDEX_MASK	0x0000000000000fffUL /* SLB index mask*/
62c3e289e1SNathan Whitehorn #define	SLBE_ESID_MASK	0xfffffffff0000000UL /* Effective segment ID mask */
63c3e289e1SNathan Whitehorn #define	SLBE_ESID_SHIFT	28
64c3e289e1SNathan Whitehorn 
65*1cd30eb6SNathan Whitehorn /* Virtual real-mode VSID in LPARs */
66*1cd30eb6SNathan Whitehorn #define VSID_VRMA	0x1ffffff
67*1cd30eb6SNathan Whitehorn 
6854c56208SNathan Whitehorn /*
6954c56208SNathan Whitehorn  * User segment for copyin/out
7054c56208SNathan Whitehorn  */
7117763042SNathan Whitehorn #define USER_SLB_SLOT 0
7254c56208SNathan Whitehorn #define USER_SLB_SLBE (((USER_ADDR >> ADDR_SR_SHFT) << SLBE_ESID_SHIFT) | \
7354c56208SNathan Whitehorn 			SLBE_VALID | USER_SLB_SLOT)
7454c56208SNathan Whitehorn 
75c3e289e1SNathan Whitehorn struct slb {
76c3e289e1SNathan Whitehorn 	uint64_t	slbv;
77c3e289e1SNathan Whitehorn 	uint64_t	slbe;
78c3e289e1SNathan Whitehorn };
79c3e289e1SNathan Whitehorn 
80c3e289e1SNathan Whitehorn #endif /* !_MACHINE_SLB_H_ */
81