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 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 65e2d6c417SLeandro Lupori /* 66e2d6c417SLeandro Lupori * SLB page sizes encoding, as present in property ibm,segment-page-sizes 67e2d6c417SLeandro Lupori * of CPU device tree node. 68e2d6c417SLeandro Lupori * 69e2d6c417SLeandro Lupori * See LoPAPR: CPU Node Properties, section C.6.1.4. 70e2d6c417SLeandro Lupori */ 71e2d6c417SLeandro Lupori #define SLB_PGSZ_4K_4K 0 72e2d6c417SLeandro Lupori 731cd30eb6SNathan Whitehorn /* Virtual real-mode VSID in LPARs */ 741cd30eb6SNathan Whitehorn #define VSID_VRMA 0x1ffffff 751cd30eb6SNathan Whitehorn 7654c56208SNathan Whitehorn /* 7754c56208SNathan Whitehorn * User segment for copyin/out 7854c56208SNathan Whitehorn */ 7917763042SNathan Whitehorn #define USER_SLB_SLOT 0 8054c56208SNathan Whitehorn #define USER_SLB_SLBE (((USER_ADDR >> ADDR_SR_SHFT) << SLBE_ESID_SHIFT) | \ 8154c56208SNathan Whitehorn SLBE_VALID | USER_SLB_SLOT) 8254c56208SNathan Whitehorn 83c3e289e1SNathan Whitehorn struct slb { 84c3e289e1SNathan Whitehorn uint64_t slbv; 85c3e289e1SNathan Whitehorn uint64_t slbe; 86c3e289e1SNathan Whitehorn }; 87c3e289e1SNathan Whitehorn 88988d63afSJustin Hibbits struct pmap; 89988d63afSJustin Hibbits void handle_kernel_slb_spill(int, register_t, register_t); 90988d63afSJustin Hibbits int handle_user_slb_spill(struct pmap *pm, vm_offset_t addr); 91988d63afSJustin Hibbits 92c3e289e1SNathan Whitehorn #endif /* !_MACHINE_SLB_H_ */ 93