1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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
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
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**************************************/
41 #ifndef __CVMX_TLB_H__
42 #define __CVMX_TLB_H__
47 * cvmx-tlb provides access functions for setting up TLB entries for simple
48 * executive applications.
50 * <hr>$Revision: 41586 $<hr>
58 * Find a free entry that can be used for share memory mapping.
60 * @return -1: no free entry found
61 * @return : a free entry
63 int cvmx_tlb_allocate_runtime_entry(void);
66 * Invalidate the TLB entry. Remove previous mapping if one was set up
69 void cvmx_tlb_free_runtime_entry(uint32_t tlbi);
72 * Debug routine to show all shared memory mapping
74 void cvmx_tlb_dump_shared_mapping(void);
77 * Program a single TLB entry to enable the provided vaddr to paddr mapping.
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
85 void cvmx_tlb_write_entry(int index, uint64_t vaddr, uint64_t paddr,
86 uint64_t size, uint64_t tlb_flags);
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
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
102 int cvmx_tlb_add_fixed_entry(uint64_t vaddr, uint64_t paddr,
103 uint64_t size, uint64_t tlb_flags);
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.
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
116 void cvmx_tlb_write_runtime_entry(int index, uint64_t vaddr, uint64_t paddr,
117 uint64_t size, uint64_t tlb_flags);
121 * Find the TLB index of a given virtual address
123 * @param vaddr The virtual address to look up
124 * @return -1 not TLB mapped
127 int cvmx_tlb_lookup(uint64_t vaddr);
130 * Debug routine to show all TLB entries of this core
133 void cvmx_tlb_dump_all(void);
137 * return the next power of two value for the given input <v>
139 * @param v input value
140 * @return next power of two value for v
142 static inline uint64_t __upper_power_of_two(uint64_t v)
157 * Check if the given value 'v' is power of two.
159 * @param v input value
163 static inline int __is_power_of_two(uint64_t v)
167 CVMX_DPOP(num_of_1s, v);
168 return (num_of_1s == 1 );