1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials provided 16 * with the distribution. 17 18 * * Neither the name of Cavium Inc. nor the names of 19 * its contributors may be used to endorse or promote products 20 * derived from this software without specific prior written 21 * permission. 22 23 * This Software, including technical data, may be subject to U.S. export control 24 * laws, including the U.S. Export Administration Act and its associated 25 * regulations, and may be subject to export or import regulations in other 26 * countries. 27 28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR 30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 38 ***********************license end**************************************/ 39 40 41#ifndef __CVMX_TLB_H__ 42#define __CVMX_TLB_H__ 43 44/** 45 * @file 46 * 47 * cvmx-tlb provides access functions for setting up TLB entries for simple 48 * executive applications. 49 * 50 * <hr>$Revision: 41586 $<hr> 51 */ 52 53#ifdef __cplusplus 54extern "C" { 55#endif 56 57/** 58 * Find a free entry that can be used for share memory mapping. 59 * 60 * @return -1: no free entry found 61 * @return : a free entry 62 */ 63int cvmx_tlb_allocate_runtime_entry(void); 64 65/** 66 * Invalidate the TLB entry. Remove previous mapping if one was set up 67 * @param tlbi 68 */ 69void cvmx_tlb_free_runtime_entry(uint32_t tlbi); 70 71/** 72 * Debug routine to show all shared memory mapping 73 */ 74void cvmx_tlb_dump_shared_mapping(void); 75 76/** 77 * Program a single TLB entry to enable the provided vaddr to paddr mapping. 78 * 79 * @param index Index of the TLB entry 80 * @param vaddr The virtual address for this mapping 81 * @param paddr The physical address for this mapping 82 * @param size Size of the mapping 83 * @param tlb_flags Entry mapping flags 84 */ 85void cvmx_tlb_write_entry(int index, uint64_t vaddr, uint64_t paddr, 86 uint64_t size, uint64_t tlb_flags); 87 88 89/** 90 * Program a single TLB entry to enable the provided vaddr to paddr mapping. 91 * This version adds a wired entry that should not be changed at run time 92 * 93 * @param index Index of the TLB entry 94 * @param vaddr The virtual address for this mapping 95 * @param paddr The physical address for this mapping 96 * @param size Size of the mapping 97 * @param tlb_flags Entry mapping flags 98 * @return -1: TLB out of entries 99 * 0: fixed entry added 100 * 101 */ 102int cvmx_tlb_add_fixed_entry(uint64_t vaddr, uint64_t paddr, 103 uint64_t size, uint64_t tlb_flags); 104 105/** 106 * Program a single TLB entry to enable the provided vaddr to paddr mapping. 107 * This version writes a runtime entry. It will check the index to make sure 108 * not to overwrite any fixed entries. 109 * 110 * @param index Index of the TLB entry 111 * @param vaddr The virtual address for this mapping 112 * @param paddr The physical address for this mapping 113 * @param size Size of the mapping 114 * @param tlb_flags Entry mapping flags 115 */ 116void cvmx_tlb_write_runtime_entry(int index, uint64_t vaddr, uint64_t paddr, 117 uint64_t size, uint64_t tlb_flags); 118 119 120/** 121 * Find the TLB index of a given virtual address 122 * 123 * @param vaddr The virtual address to look up 124 * @return -1 not TLB mapped 125 * >=0 TLB TLB index 126 */ 127int cvmx_tlb_lookup(uint64_t vaddr); 128 129/** 130 * Debug routine to show all TLB entries of this core 131 * 132 */ 133void cvmx_tlb_dump_all(void); 134 135/* 136 * @INTERNAL 137 * return the next power of two value for the given input <v> 138 * 139 * @param v input value 140 * @return next power of two value for v 141 */ 142static inline uint64_t __upper_power_of_two(uint64_t v) 143{ 144 v--; 145 v |= v >> 1; 146 v |= v >> 2; 147 v |= v >> 4; 148 v |= v >> 8; 149 v |= v >> 16; 150 v |= v >> 32; 151 v++; 152 return v; 153} 154 155/** 156 * @INTERNAL 157 * Check if the given value 'v' is power of two. 158 * 159 * @param v input value 160 * @return 1 yes 161 * 0 no 162 */ 163static inline int __is_power_of_two(uint64_t v) 164{ 165 int num_of_1s = 0; 166 167 CVMX_DPOP(num_of_1s, v); 168 return (num_of_1s == 1 ); 169} 170 171#ifdef __cplusplus 172} 173#endif 174 175#endif 176