xref: /freebsd/sys/powerpc/include/slb.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1c3e289e1SNathan Whitehorn /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
371e3c308SPedro F. Giffuni  *
4c3e289e1SNathan Whitehorn  * Copyright (C) 2009 Nathan Whitehorn
5c3e289e1SNathan Whitehorn  * All rights reserved.
6c3e289e1SNathan Whitehorn  *
7c3e289e1SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
8c3e289e1SNathan Whitehorn  * modification, are permitted provided that the following conditions
9c3e289e1SNathan Whitehorn  * are met:
10c3e289e1SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
11c3e289e1SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
12c3e289e1SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
13c3e289e1SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
14c3e289e1SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
15c3e289e1SNathan Whitehorn  *
16c3e289e1SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17c3e289e1SNathan Whitehorn  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18c3e289e1SNathan Whitehorn  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19c3e289e1SNathan Whitehorn  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20c3e289e1SNathan Whitehorn  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21c3e289e1SNathan Whitehorn  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22c3e289e1SNathan Whitehorn  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23c3e289e1SNathan Whitehorn  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24c3e289e1SNathan Whitehorn  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25c3e289e1SNathan Whitehorn  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26c3e289e1SNathan Whitehorn  *
27c3e289e1SNathan Whitehorn  * $FreeBSD$
28c3e289e1SNathan Whitehorn  */
29c3e289e1SNathan Whitehorn 
30c3e289e1SNathan Whitehorn #ifndef _MACHINE_SLB_H_
31c3e289e1SNathan Whitehorn #define	_MACHINE_SLB_H_
32c3e289e1SNathan Whitehorn 
33c3e289e1SNathan Whitehorn /*
34c3e289e1SNathan Whitehorn  * Bit definitions for segment lookaside buffer entries.
35c3e289e1SNathan Whitehorn  *
36c3e289e1SNathan Whitehorn  * PowerPC Microprocessor Family: The Programming Environments for 64-bit
37c3e289e1SNathan Whitehorn  * Microprocessors, section 7.4.2.1
38c3e289e1SNathan Whitehorn  *
39c3e289e1SNathan Whitehorn  * Note that these bitmasks are relative to the values for one of the two
40c3e289e1SNathan Whitehorn  * values for slbmte, slbmfee, and slbmfev, not the internal SLB
41c3e289e1SNathan Whitehorn  * representation.
42c3e289e1SNathan Whitehorn  */
43c3e289e1SNathan Whitehorn 
44c3e289e1SNathan Whitehorn #define	SLBV_KS		0x0000000000000800UL /* Supervisor-state prot key */
45c3e289e1SNathan Whitehorn #define	SLBV_KP		0x0000000000000400UL /* User-state prot key */
46c3e289e1SNathan Whitehorn #define	SLBV_N		0x0000000000000200UL /* No-execute protection */
47c3e289e1SNathan Whitehorn #define	SLBV_L		0x0000000000000100UL /* Large page selector */
48c3e289e1SNathan Whitehorn #define	SLBV_CLASS	0x0000000000000080UL /* Class selector */
49c3e289e1SNathan Whitehorn #define	SLBV_VSID_MASK	0xfffffffffffff000UL /* Virtual segment ID mask */
50c3e289e1SNathan Whitehorn #define	SLBV_VSID_SHIFT	12
51c3e289e1SNathan Whitehorn 
52c3e289e1SNathan Whitehorn /*
533b4b3830SNathan Whitehorn  * Make a predictable 1:1 map from ESIDs to VSIDs for the kernel. Hash table
543b4b3830SNathan Whitehorn  * coverage is increased by swizzling the ESID and multiplying by a prime
553b4b3830SNathan Whitehorn  * number (0x13bb).
56c3e289e1SNathan Whitehorn  */
573b4b3830SNathan Whitehorn #define	KERNEL_VSID_BIT	0x0000001000000000UL /* Bit set in all kernel VSIDs */
583b4b3830SNathan Whitehorn #define KERNEL_VSID(esid) ((((((uint64_t)esid << 8) | ((uint64_t)esid >> 28)) \
593b4b3830SNathan Whitehorn 				* 0x13bbUL) & (KERNEL_VSID_BIT - 1)) | \
603b4b3830SNathan Whitehorn 				KERNEL_VSID_BIT)
61c3e289e1SNathan Whitehorn 
62c3e289e1SNathan Whitehorn #define	SLBE_VALID	0x0000000008000000UL /* SLB entry valid */
63c3e289e1SNathan Whitehorn #define	SLBE_INDEX_MASK	0x0000000000000fffUL /* SLB index mask*/
64c3e289e1SNathan Whitehorn #define	SLBE_ESID_MASK	0xfffffffff0000000UL /* Effective segment ID mask */
65c3e289e1SNathan Whitehorn #define	SLBE_ESID_SHIFT	28
66c3e289e1SNathan Whitehorn 
67e2d6c417SLeandro Lupori /*
68e2d6c417SLeandro Lupori  * SLB page sizes encoding, as present in property ibm,segment-page-sizes
69e2d6c417SLeandro Lupori  * of CPU device tree node.
70e2d6c417SLeandro Lupori  *
71e2d6c417SLeandro Lupori  * See LoPAPR: CPU Node Properties, section C.6.1.4.
72e2d6c417SLeandro Lupori  */
73e2d6c417SLeandro Lupori #define	SLB_PGSZ_4K_4K	0
74e2d6c417SLeandro Lupori 
751cd30eb6SNathan Whitehorn /* Virtual real-mode VSID in LPARs */
761cd30eb6SNathan Whitehorn #define VSID_VRMA	0x1ffffff
771cd30eb6SNathan Whitehorn 
7854c56208SNathan Whitehorn /*
7954c56208SNathan Whitehorn  * User segment for copyin/out
8054c56208SNathan Whitehorn  */
8117763042SNathan Whitehorn #define USER_SLB_SLOT 0
8254c56208SNathan Whitehorn #define USER_SLB_SLBE (((USER_ADDR >> ADDR_SR_SHFT) << SLBE_ESID_SHIFT) | \
8354c56208SNathan Whitehorn 			SLBE_VALID | USER_SLB_SLOT)
8454c56208SNathan Whitehorn 
85c3e289e1SNathan Whitehorn struct slb {
86c3e289e1SNathan Whitehorn 	uint64_t	slbv;
87c3e289e1SNathan Whitehorn 	uint64_t	slbe;
88c3e289e1SNathan Whitehorn };
89c3e289e1SNathan Whitehorn 
90988d63afSJustin Hibbits struct pmap;
91988d63afSJustin Hibbits void	handle_kernel_slb_spill(int, register_t, register_t);
92988d63afSJustin Hibbits int	handle_user_slb_spill(struct pmap *pm, vm_offset_t addr);
93988d63afSJustin Hibbits 
94c3e289e1SNathan Whitehorn #endif /* !_MACHINE_SLB_H_ */
95