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**************************************/
44 * This is file defines ASM primitives for sim magic functions.
46 * <hr>$Revision: 70030 $<hr>
50 #ifndef __CVMX_SIM_MAGIC_H__
51 #define __CVMX_SIM_MAGIC_H__
57 /* Note, the following Magic function are only useful in the simulator
58 * environment. Typical simple executive application should not use
59 * these functions. Their access functions are defined and implemented in
72 /* Assembler macros for accessing simulator magic functions */
73 #define OCTEON_SIM_MAGIC_TRAP_ADDRESS 0x8000000feffe0000ull
75 /* Reg t9 (r25) specifies the actual magic function*/
76 #define SIM_MAGIC_PUTS 0x05
77 #define SIM_MAGIC_SIMPRINTF 0x06
78 #define SIM_MAGIC_WRITE 0x07
79 #define SIM_MAGIC_READ 0x08
80 #define SIM_MAGIC_OPEN 0x09
81 #define SIM_MAGIC_CLOSE 0x0A
82 #define SIM_MAGIC_STAT 0x0B
83 #define SIM_MAGIC_FSTAT 0x0C
84 #define SIM_MAGIC_LSEEK 0x0D
85 #define SIM_MAGIC_ALLOC_MEM 0x20
86 #define SIM_MAGIC_GET_CPUFREQ 0x31 /* SDK 1.9 release and after */
87 #define SIM_MAGIC_GET_MEMFREQ 0x32 /* SDK 1.9 release and after */
88 #define SIM_MAGIC_GET_IOFREQ 0x33 /* SDK 2.0 release and after, only set in Octeon2 */
92 * sim_magci implementation function with return code.
94 * @param func_no SIM magic function to invoke
96 * @return Result of the SIM magic function
98 static inline int __cvmx_sim_magic_return(unsigned long long func_no)
100 register unsigned long long magic_addr asm ("$15");
101 register unsigned long long magic_func asm ("$25"); /* t9 */
104 magic_addr = OCTEON_SIM_MAGIC_TRAP_ADDRESS;
105 magic_func = func_no;
107 "dadd $24, $31, $0 \n"
109 "dadd $31, $24, $0 \n"
112 : "r" (magic_addr), "r" (magic_func)
121 * sim_magci implementation function without return code.
123 * @param func_no SIM magic function to invoke
125 static inline void __cvmx_sim_magic_no_return(unsigned long long func_no)
127 register unsigned long long magic_addr asm ("$15");
128 register unsigned long long magic_func asm ("$25"); /* t9 */
130 magic_addr = OCTEON_SIM_MAGIC_TRAP_ADDRESS;
131 magic_func = func_no;
133 "dadd $24, $31, $0 \n"
135 "dadd $31, $24, $0 \n"
137 : "r" (magic_addr), "r" (magic_func)
144 * SIM magic printf function, only support up to 8 parameters
148 static inline void __cvmx_sim_magic_simprintf(const char *format, ...)
152 __cvmx_sim_magic_no_return( SIM_MAGIC_SIMPRINTF);
156 * Retrive cpu core clock frequency from the simulator
158 * @return simulating core frequency
160 static inline int cvmx_sim_magic_get_cpufreq(void)
164 return __cvmx_sim_magic_return(SIM_MAGIC_GET_CPUFREQ);
168 * Retrive DDR clock frequency from the simulator
170 * @return simulating DDR frequency
172 static inline int cvmx_sim_magic_get_memfreq(void)
176 return __cvmx_sim_magic_return(SIM_MAGIC_GET_MEMFREQ);
180 * Retrive io core clock frequency from the simulator
182 * @return simulating core frequency
184 static inline int cvmx_sim_magic_get_iofreq(void)
188 if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_MODEL(OCTEON_CNF7XXX))
189 return __cvmx_sim_magic_return(SIM_MAGIC_GET_IOFREQ);
198 #endif /* __CVMX_SIM_MAGIC_H__ */