1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (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 Networks 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 NETWORKS 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>
57 #define CVMX_TLB_PAGEMASK_4K (0x3 << 11)
58 #define CVMX_TLB_PAGEMASK_16K (0xF << 11)
59 #define CVMX_TLB_PAGEMASK_64K (0x3F << 11)
60 #define CVMX_TLB_PAGEMASK_256K (0xFF << 11)
61 #define CVMX_TLB_PAGEMASK_1M (0x3FF << 11)
62 #define CVMX_TLB_PAGEMASK_4M (0xFFF << 11)
63 #define CVMX_TLB_PAGEMASK_16M (0x3FFF << 11)
64 #define CVMX_TLB_PAGEMASK_64M (0xFFFF << 11)
65 #define CVMX_TLB_PAGEMASK_256M (0x3FFFF << 11)
67 #define PAGE_MASK ( ~(( 1<< 12 ) -1))
70 * Set up a wired entry. This function is designed to be used by Simple
71 * Executive to set up its virtual to physical address mapping at start up
72 * time. After the mapping is set up, the remaining unused TLB entries can
73 * be use for run time shared memory mapping.
75 * Calling this function causes the C0 wired index register to increase.
76 * Wired index register points to the separation between fixed TLB mapping
77 * and run time shared memory mapping.
80 * @param lo0 Entry Low0
81 * @param lo1 Entry Low1
82 * @pagam pagemask Pagemask
84 * @return 0: the entry is added
85 * @return -1: out of TLB entry
87 int cvmx_tlb_add_wired_entry( uint64_t hi, uint64_t lo0,
88 uint64_t lo1, uint64_t pagemask);
92 * Find a free entry that can be used for share memory mapping.
94 * @return -1: no free entry found
95 * @return : a free entry
97 int cvmx_tlb_allocate_runtime_entry(void);
100 * Invalidate the TLB entry. Remove previous mapping if one was set up
103 void cvmx_tlb_free_runtime_entry(uint32_t tlbi);
106 * Debug routine to show all shared memory mapping
108 void cvmx_tlb_dump_shared_mapping(void);
111 * Program a single TLB entry to enable the provided vaddr to paddr mapping.
113 * @param index Index of the TLB entry
114 * @param vaddr The virtual address for this mapping
115 * @param paddr The physical address for this mapping
116 * @param size Size of the mapping
117 * @param tlb_flags Entry mapping flags
119 void cvmx_tlb_write_entry(int index, uint64_t vaddr, uint64_t paddr,
120 uint64_t size, uint64_t tlb_flags);
124 * Program a single TLB entry to enable the provided vaddr to paddr mapping.
125 * This version adds a wired entry that should not be changed at run time
127 * @param index Index of the TLB entry
128 * @param vaddr The virtual address for this mapping
129 * @param paddr The physical address for this mapping
130 * @param size Size of the mapping
131 * @param tlb_flags Entry mapping flags
132 * @return -1: TLB out of entries
133 * 0: fixed entry added
136 int cvmx_tlb_add_fixed_entry(uint64_t vaddr, uint64_t paddr,
137 uint64_t size, uint64_t tlb_flags);
140 * Program a single TLB entry to enable the provided vaddr to paddr mapping.
141 * This version writes a runtime entry. It will check the index to make sure
142 * not to overwrite any fixed entries.
144 * @param index Index of the TLB entry
145 * @param vaddr The virtual address for this mapping
146 * @param paddr The physical address for this mapping
147 * @param size Size of the mapping
148 * @param tlb_flags Entry mapping flags
150 void cvmx_tlb_write_runtime_entry(int index, uint64_t vaddr, uint64_t paddr,
151 uint64_t size, uint64_t tlb_flags);
155 * Find the TLB index of a given virtual address
157 * @param vaddr The virtual address to look up
158 * @return -1 not TLB mapped
161 int cvmx_tlb_lookup(uint64_t vaddr);
164 * Debug routine to show all TLB entries of this core
167 void cvmx_tlb_dump_all(void);
170 * Query for total number of TLBs of the core
172 * @return Total number of TLB entries available on the core
174 static inline uint32_t cvmx_tlb_size_limit(void)
176 uint32_t tlb_size_limit = 0;
178 if (OCTEON_IS_MODEL(OCTEON_CN63XX)) tlb_size_limit = 128;
179 else if (OCTEON_IS_MODEL(OCTEON_CN5XXX)) tlb_size_limit = 64;
180 else if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) tlb_size_limit = 32;
182 return tlb_size_limit;
187 * return the next power of two value for the given input <v>
189 * @param v input value
190 * @return next power of two value for v
192 static inline uint64_t __upper_power_of_two(uint64_t v)
207 * Check if the given value 'v' is power of two.
209 * @param v input value
213 static inline int __is_power_of_two(uint64_t v)
217 CVMX_DPOP(num_of_1s, v);
218 return (num_of_1s == 1 );
225 * Find last bit set 64bit version
227 * @param x the integer to find leading 1
229 * @return >=0 the bit position (0..63) of the most significant 1 bit in a word
230 * -1 if no 1 bit exists
232 static inline uint64_t __fls64(uint64_t x)
236 if (sizeof(x) != 8) return 0;
251 * Compute log2(v), only works if v is power of two.
253 * @param v the input value
256 static inline uint32_t __log2(uint64_t v)
260 if (v) log2 = __fls64(v);