2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright 2003-2011 Netlogic Microsystems (Netlogic). All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY Netlogic Microsystems ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __NLM_MIPS_EXTNS_H__
35 #define __NLM_MIPS_EXTNS_H__
37 #if !defined(LOCORE) && !defined(__ASSEMBLY__)
38 static __inline__ int32_t nlm_swapw(int32_t *loc, int32_t val)
42 __asm__ __volatile__ (
47 ".word 0x71280014\n" /* "swapw $8, $9\n" */
50 : "+m" (*loc), "=r" (oldval)
51 : "r" (loc), "r" (val)
57 static __inline__ uint32_t nlm_swapwu(int32_t *loc, uint32_t val)
61 __asm__ __volatile__ (
66 ".word 0x71280015\n" /* "swapwu $8, $9\n" */
69 : "+m" (*loc), "=r" (oldval)
70 : "r" (loc), "r" (val)
77 static __inline__ uint64_t nlm_swapd(int32_t *loc, uint64_t val)
81 __asm__ __volatile__ (
86 ".word 0x71280014\n" /* "swapw $8, $9\n" */
89 : "+m" (*loc), "=r" (oldval)
90 : "r" (loc), "r" (val)
98 * Atomic increment a unsigned int
100 static __inline unsigned int
101 nlm_ldaddwu(unsigned int value, unsigned int *addr)
103 __asm__ __volatile__(
108 ".word 0x71280011\n" /* ldaddwu $8, $9 */
111 : "=&r"(value), "+m"(*addr)
112 : "0"(value), "r" ((unsigned long)addr)
118 * 32 bit read write for c0
120 #define read_c0_register32(reg, sel) \
123 __asm__ __volatile__( \
126 "mfc0 %0, $%1, %2\n\t" \
128 : "=r" (__rv) : "i" (reg), "i" (sel) ); \
132 #define write_c0_register32(reg, sel, value) \
133 __asm__ __volatile__( \
136 "mtc0 %0, $%1, %2\n\t" \
138 : : "r" (value), "i" (reg), "i" (sel) );
140 #if defined(__mips_n64) || defined(__mips_n32)
142 * On 64 bit compilation, the operations are simple
144 #define read_c0_register64(reg, sel) \
147 __asm__ __volatile__( \
150 "dmfc0 %0, $%1, %2\n\t" \
152 : "=r" (__rv) : "i" (reg), "i" (sel) ); \
156 #define write_c0_register64(reg, sel, value) \
157 __asm__ __volatile__( \
160 "dmtc0 %0, $%1, %2\n\t" \
162 : : "r" (value), "i" (reg), "i" (sel) );
163 #else /* ! (defined(__mips_n64) || defined(__mips_n32)) */
166 * 32 bit compilation, 64 bit values has to split
168 #define read_c0_register64(reg, sel) \
170 uint32_t __high, __low; \
171 __asm__ __volatile__( \
173 ".set noreorder\n\t" \
175 "dmfc0 $8, $%2, %3\n\t" \
176 "dsra32 %0, $8, 0\n\t" \
177 "sll %1, $8, 0\n\t" \
179 : "=r"(__high), "=r"(__low): "i"(reg), "i"(sel) \
181 ((uint64_t)__high << 32) | __low; \
184 #define write_c0_register64(reg, sel, value) \
186 uint32_t __high = value >> 32; \
187 uint32_t __low = value & 0xffffffff; \
188 __asm__ __volatile__( \
190 ".set noreorder\n\t" \
192 "dsll32 $8, %1, 0\n\t" \
193 "dsll32 $9, %0, 0\n\t" \
194 "dsrl32 $8, $8, 0\n\t" \
195 "or $8, $8, $9\n\t" \
196 "dmtc0 $8, $%2, %3\n\t" \
198 :: "r"(__high), "r"(__low), "i"(reg), "i"(sel) \
203 /* functions to write to and read from the extended
205 * EIRR : Extended Interrupt Request Register
206 * cp0 register 9 sel 6
207 * bits 0...7 are same as cause register 8...15
208 * EIMR : Extended Interrupt Mask Register
209 * cp0 register 9 sel 7
210 * bits 0...7 are same as status register 8...15
212 static __inline uint64_t
213 nlm_read_c0_eirr(void)
216 return (read_c0_register64(9, 6));
220 nlm_write_c0_eirr(uint64_t val)
223 write_c0_register64(9, 6, val);
226 static __inline uint64_t
227 nlm_read_c0_eimr(void)
230 return (read_c0_register64(9, 7));
234 nlm_write_c0_eimr(uint64_t val)
237 write_c0_register64(9, 7, val);
240 static __inline__ uint32_t
241 nlm_read_c0_ebase(void)
244 return (read_c0_register32(15, 1));
247 static __inline__ int
250 return (nlm_read_c0_ebase() >> 5) & 0x3;
253 static __inline__ int
256 return nlm_read_c0_ebase() & 0x1f;
259 static __inline__ int
262 return nlm_read_c0_ebase() & 0x3;
265 static __inline__ int
268 return (nlm_read_c0_ebase() >> 2) & 0x7;
272 #define XLP_MAX_NODES 4
273 #define XLP_MAX_CORES 8
274 #define XLP_MAX_THREADS 4