slb.h revision 214574
1177633Sdfr/*-
2177633Sdfr * Copyright (C) 2009 Nathan Whitehorn
3177633Sdfr * All rights reserved.
4177633Sdfr *
5177633Sdfr * Redistribution and use in source and binary forms, with or without
6177633Sdfr * modification, are permitted provided that the following conditions
7177633Sdfr * are met:
8177633Sdfr * 1. Redistributions of source code must retain the above copyright
9177633Sdfr *    notice, this list of conditions and the following disclaimer.
10177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright
11177633Sdfr *    notice, this list of conditions and the following disclaimer in the
12177633Sdfr *    documentation and/or other materials provided with the distribution.
13177633Sdfr *
14177633Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15177633Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16177633Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17177633Sdfr * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18177633Sdfr * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19177633Sdfr * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20177633Sdfr * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21177633Sdfr * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22177633Sdfr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23177633Sdfr * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24177633Sdfr *
25177633Sdfr * $FreeBSD: head/sys/powerpc/include/slb.h 214574 2010-10-30 23:07:30Z nwhitehorn $
26177633Sdfr */
27177633Sdfr
28177633Sdfr#ifndef _MACHINE_SLB_H_
29177633Sdfr#define	_MACHINE_SLB_H_
30177633Sdfr
31177633Sdfr/*
32177633Sdfr * Bit definitions for segment lookaside buffer entries.
33177633Sdfr *
34177633Sdfr * PowerPC Microprocessor Family: The Programming Environments for 64-bit
35177633Sdfr * Microprocessors, section 7.4.2.1
36177633Sdfr *
37177633Sdfr * Note that these bitmasks are relative to the values for one of the two
38177633Sdfr * values for slbmte, slbmfee, and slbmfev, not the internal SLB
39177633Sdfr * representation.
40177633Sdfr */
41177633Sdfr
42177633Sdfr#define	SLBV_KS		0x0000000000000800UL /* Supervisor-state prot key */
43177633Sdfr#define	SLBV_KP		0x0000000000000400UL /* User-state prot key */
44177633Sdfr#define	SLBV_N		0x0000000000000200UL /* No-execute protection */
45177633Sdfr#define	SLBV_L		0x0000000000000100UL /* Large page selector */
46177633Sdfr#define	SLBV_CLASS	0x0000000000000080UL /* Class selector */
47177633Sdfr#define	SLBV_VSID_MASK	0xfffffffffffff000UL /* Virtual segment ID mask */
48177633Sdfr#define	SLBV_VSID_SHIFT	12
49177633Sdfr
50177633Sdfr/*
51177633Sdfr * Make a predictable 1:1 map from ESIDs to VSIDs for the kernel. Hash table
52177633Sdfr * coverage is increased by swizzling the ESID and multiplying by a prime
53177633Sdfr * number (0x13bb).
54177633Sdfr */
55177633Sdfr#define	KERNEL_VSID_BIT	0x0000001000000000UL /* Bit set in all kernel VSIDs */
56177633Sdfr#define KERNEL_VSID(esid) ((((((uint64_t)esid << 8) | ((uint64_t)esid >> 28)) \
57177633Sdfr				* 0x13bbUL) & (KERNEL_VSID_BIT - 1)) | \
58177633Sdfr				KERNEL_VSID_BIT)
59177633Sdfr
60177633Sdfr#define	SLBE_VALID	0x0000000008000000UL /* SLB entry valid */
61177633Sdfr#define	SLBE_INDEX_MASK	0x0000000000000fffUL /* SLB index mask*/
62177633Sdfr#define	SLBE_ESID_MASK	0xfffffffff0000000UL /* Effective segment ID mask */
63177633Sdfr#define	SLBE_ESID_SHIFT	28
64177633Sdfr
65177633Sdfr/*
66177633Sdfr * User segment for copyin/out
67177633Sdfr */
68184921Sdfr#define USER_SLB_SLOT 63
69177633Sdfr#define USER_SLB_SLBE (((USER_ADDR >> ADDR_SR_SHFT) << SLBE_ESID_SHIFT) | \
70177633Sdfr			SLBE_VALID | USER_SLB_SLOT)
71177633Sdfr
72177633Sdfrstruct slb {
73177633Sdfr	uint64_t	slbv;
74177633Sdfr	uint64_t	slbe;
75177633Sdfr};
76177633Sdfr
77177633Sdfr#endif /* !_MACHINE_SLB_H_ */
78177633Sdfr