cvmx-sim-magic.h revision 215976
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Networks (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 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 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 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**************************************/ 39 40 41/** 42 * @file 43 * 44 * This is file defines ASM primitives for sim magic functions. 45 46 * <hr>$Revision: 49448 $<hr> 47 * 48 * 49 */ 50#ifndef __CVMX_SIM_MAGIC_H__ 51#define __CVMX_SIM_MAGIC_H__ 52 53#ifdef __cplusplus 54extern "C" { 55#endif 56 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 60 * the newlib 61 * SIM_MAGIC_PUTS 62 * SIM_MAGIC_WRITE 63 * SIM_MAGIC_READ 64 * SIM_MAGIC_OPEN 65 * SIM_MAGIC_CLOSE 66 * SIM_MAGIC_STAT 67 * SIM_MAGIC_FSTAT 68 * SIM_MAGIC_LSEEK 69 * SIM_MAGIC_ALLOC_MEM 70 */ 71 72/* Assembler macros for accessing simulator magic functions */ 73#define OCTEON_SIM_MAGIC_TRAP_ADDRESS 0x8000000feffe0000ull 74 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 */ 89 90/** 91 * @INTERNAL 92 * sim_magci implementation function with return code. 93 * 94 * @param func_no SIM magic function to invoke 95 * 96 * @return Result of the SIM magic function 97 */ 98static inline int __cvmx_sim_magic_return(unsigned long long func_no) 99{ 100 register unsigned long long magic_addr asm ("$15"); 101 register unsigned long long magic_func asm ("$25"); /* t9 */ 102 int ret; 103 104 magic_addr = OCTEON_SIM_MAGIC_TRAP_ADDRESS; 105 magic_func = func_no; 106 asm volatile ( 107 "dadd $24, $31, $0 \n" 108 "jalr $15 \n" 109 "dadd $31, $24, $0 \n" 110 "move %0, $2" 111 : "=r" (ret) 112 : "r" (magic_addr), "r" (magic_func) 113 : "$2", "$24" ); 114 115 116 return ret; 117} 118 119/** 120 * @INTERNAL 121 * sim_magci implementation function without return code. 122 * 123 * @param func_no SIM magic function to invoke 124 */ 125static inline void __cvmx_sim_magic_no_return(unsigned long long func_no) 126{ 127 register unsigned long long magic_addr asm ("$15"); 128 register unsigned long long magic_func asm ("$25"); /* t9 */ 129 130 magic_addr = OCTEON_SIM_MAGIC_TRAP_ADDRESS; 131 magic_func = func_no; 132 asm volatile ( 133 "dadd $24, $31, $0 \n" 134 "jalr $15 \n" 135 "dadd $31, $24, $0 \n" 136 : 137 : "r" (magic_addr), "r" (magic_func) 138 : "$24" ); 139 140} 141 142/** 143 * @INTERNAL 144 * SIM magic printf function, only support up to 8 parameters 145 * 146 * @param format 147 */ 148static inline void __cvmx_sim_magic_simprintf(const char *format, ...) 149{ 150 CVMX_SYNC; 151 152 __cvmx_sim_magic_no_return( SIM_MAGIC_SIMPRINTF); 153} 154 155/** 156 * Retrive cpu core clock frequency from the simulator 157 * 158 * @return simulating core frequency 159 */ 160static inline int cvmx_sim_magic_get_cpufreq(void) 161{ 162 CVMX_SYNC; 163 164 return __cvmx_sim_magic_return(SIM_MAGIC_GET_CPUFREQ); 165} 166 167/** 168 * Retrive DDR clock frequency from the simulator 169 * 170 * @return simulating DDR frequency 171 */ 172static inline int cvmx_sim_magic_get_memfreq(void) 173{ 174 CVMX_SYNC; 175 176 return __cvmx_sim_magic_return(SIM_MAGIC_GET_MEMFREQ); 177} 178 179/** 180 * Retrive io core clock frequency from the simulator 181 * 182 * @return simulating core frequency 183 */ 184static inline int cvmx_sim_magic_get_iofreq(void) 185{ 186 CVMX_SYNC; 187 188 if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) 189 return __cvmx_sim_magic_return(SIM_MAGIC_GET_IOFREQ); 190 else 191 return 0; 192} 193 194#ifdef __cplusplus 195} 196#endif 197 198#endif /* __CVMX_SIM_MAGIC_H__ */ 199