tlb.h revision 80709
1/*- 2 * Copyright (c) 2001 Jake Burkholder. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/sparc64/include/tlb.h 80709 2001-07-31 06:05:05Z jake $ 27 */ 28 29#ifndef _MACHINE_TLB_H_ 30#define _MACHINE_TLB_H_ 31 32#define TLB_SLOT_COUNT 64 33 34#define TLB_SLOT_TSB_KERNEL_MIN 60 /* XXX */ 35#define TLB_SLOT_TSB_USER_PRIMARY 61 36#define TLB_SLOT_TSB_USER_SECONDARY 62 37#define TLB_SLOT_KERNEL 63 38 39#define TLB_DAR_SLOT_SHIFT (3) 40#define TLB_DAR_SLOT(slot) ((slot) << TLB_DAR_SLOT_SHIFT) 41 42#define TLB_TAR_VA(va) ((va) & ~PAGE_MASK) 43#define TLB_TAR_CTX(ctx) (ctx) 44 45#define TLB_DEMAP_ID_SHIFT (4) 46#define TLB_DEMAP_ID_PRIMARY (0) 47#define TLB_DEMAP_ID_SECONDARY (1) 48#define TLB_DEMAP_ID_NUCLEUS (2) 49 50#define TLB_DEMAP_TYPE_SHIFT (6) 51#define TLB_DEMAP_TYPE_PAGE (0) 52#define TLB_DEMAP_TYPE_CONTEXT (1) 53 54#define TLB_DEMAP_VA(va) ((va) & ~PAGE_MASK) 55#define TLB_DEMAP_ID(id) ((id) << TLB_DEMAP_ID_SHIFT) 56#define TLB_DEMAP_TYPE(type) ((type) << TLB_DEMAP_TYPE_SHIFT) 57 58#define TLB_DEMAP_PAGE (TLB_DEMAP_TYPE(TLB_DEMAP_TYPE_PAGE)) 59#define TLB_DEMAP_CONTEXT (TLB_DEMAP_TYPE(TLB_DEMAP_TYPE_CONTEXT)) 60 61#define TLB_DEMAP_PRIMARY (TLB_DEMAP_ID(TLB_DEMAP_ID_PRIMARY)) 62#define TLB_DEMAP_SECONDARY (TLB_DEMAP_ID(TLB_DEMAP_ID_SECONDARY)) 63#define TLB_DEMAP_NUCLEUS (TLB_DEMAP_ID(TLB_DEMAP_ID_NUCLEUS)) 64 65#define TLB_CTX_KERNEL (0) 66 67#define TLB_DTLB (1 << 0) 68#define TLB_ITLB (1 << 1) 69 70static __inline void 71tlb_dtlb_page_demap(u_int ctx, vm_offset_t va) 72{ 73 if (ctx == TLB_CTX_KERNEL) { 74 stxa(TLB_DEMAP_VA(va) | TLB_DEMAP_NUCLEUS | TLB_DEMAP_PAGE, 75 ASI_DMMU_DEMAP, 0); 76 membar(Sync); 77 } else 78 TODO; 79} 80 81static __inline void 82tlb_dtlb_store(vm_offset_t va, struct tte tte) 83{ 84 stxa(AA_DMMU_TAR, ASI_DMMU, TLB_TAR_VA(va) | TLB_TAR_CTX(0)); 85 stxa(0, ASI_DTLB_DATA_IN_REG, tte.tte_data); 86 membar(Sync); 87} 88 89static __inline void 90tlb_dtlb_store_slot(vm_offset_t va, struct tte tte, int slot) 91{ 92 stxa(AA_DMMU_TAR, ASI_DMMU, TLB_TAR_VA(va) | TLB_TAR_CTX(0)); 93 stxa(TLB_DAR_SLOT(slot), ASI_DTLB_DATA_ACCESS_REG, tte.tte_data); 94 membar(Sync); 95} 96 97static __inline void 98tlb_itlb_page_demap(u_int ctx, vm_offset_t va) 99{ 100 if (ctx == TLB_CTX_KERNEL) { 101 stxa(TLB_DEMAP_VA(va) | TLB_DEMAP_NUCLEUS | TLB_DEMAP_PAGE, 102 ASI_IMMU_DEMAP, 0); 103 flush(KERNBASE); 104 } else 105 TODO; 106} 107 108static __inline void 109tlb_itlb_store(vm_offset_t va, struct tte tte) 110{ 111 TODO; 112} 113 114static __inline void 115tlb_itlb_store_slot(vm_offset_t va, struct tte tte, int slot) 116{ 117 stxa(AA_IMMU_TAR, ASI_IMMU, TLB_TAR_VA(va) | TLB_TAR_CTX(0)); 118 stxa(TLB_DAR_SLOT(slot), ASI_ITLB_DATA_ACCESS_REG, tte.tte_data); 119 flush(va); 120} 121 122static __inline void 123tlb_page_demap(u_int tlb, u_int ctx, vm_offset_t va) 124{ 125 if (tlb & TLB_DTLB) 126 tlb_dtlb_page_demap(ctx, va); 127 if (tlb & TLB_ITLB) 128 tlb_itlb_page_demap(ctx, va); 129} 130 131static __inline void 132tlb_store(u_int tlb, vm_offset_t va, struct tte tte) 133{ 134 if (tlb & TLB_DTLB) 135 tlb_dtlb_store(va, tte); 136 if (tlb & TLB_ITLB) 137 tlb_itlb_store(va, tte); 138} 139 140static __inline void 141tlb_store_slot(u_int tlb, vm_offset_t va, struct tte tte, int slot) 142{ 143 if (tlb & TLB_DTLB) 144 tlb_dtlb_store_slot(va, tte, slot); 145 if (tlb & TLB_ITLB) 146 tlb_itlb_store_slot(va, tte, slot); 147} 148 149#endif /* !_MACHINE_TLB_H_ */ 150