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**************************************/
43 * Function prototypes for accessing memory and CSRs on Octeon.
45 * <hr>$Revision: 38306 $<hr>
47 #ifndef __CVMX_ACCESS_H__
48 #define __CVMX_ACCESS_H__
54 /* We're going to assume that if we are compiling for Mips then we must be
55 running natively on Octoen. It is possible that this code could be
56 compiled on a non Octeon Mips that is acting as a PCI/PCIe host. In this
57 case this assumption will be wrong and cause issues We can't key off of
58 __octeon__ since some people use stock gcc toolchains */
59 #if defined(__mips__) && !defined(CVMX_BUILD_FOR_LINUX_HOST)
60 #define CVMX_FUNCTION static inline
62 #define CVMX_FUNCTION extern
66 * simprintf uses simulator tricks to speed up printouts. The format
67 * and args are passed to the simulator and processed natively on the host.
68 * Simprintf is limited to 7 arguments, and they all must use %ll (long long)
69 * format specifiers to be displayed correctly.
75 EXTERN_ASM void simprintf(const char *format, ...);
78 * This function performs some default initialization of the Octeon executive.
79 * It initializes the cvmx_bootmem memory allocator with the list of physical
80 * memory provided by the bootloader, and creates 1-1 TLB mappings for this
81 * memory. This function should be called on all cores that will use either the
82 * bootmem allocator or the 1-1 TLB mappings. Applications which require a
83 * different configuration can replace this function with a suitable application
86 * @return 0 on success
89 extern int cvmx_user_app_init(void);
92 * Returns the Octeon processor ID.
94 * @return Octeon processor ID from COP0
96 CVMX_FUNCTION uint32_t cvmx_get_proc_id(void) __attribute__ ((pure));
99 * Convert a memory pointer (void*) into a hardware compatable
100 * memory address (uint64_t). Octeon hardware widgets don't
101 * understand logical addresses.
103 * @param ptr C style memory pointer
104 * @return Hardware physical address
106 CVMX_FUNCTION uint64_t cvmx_ptr_to_phys(void *ptr);
109 * Convert a hardware physical address (uint64_t) into a
110 * memory pointer (void *).
112 * @param physical_address
113 * Hardware physical address to memory
114 * @return Pointer to memory
116 CVMX_FUNCTION void *cvmx_phys_to_ptr(uint64_t physical_address);
118 CVMX_FUNCTION void cvmx_write64_int64(uint64_t address, int64_t value);
119 CVMX_FUNCTION void cvmx_write64_uint64(uint64_t address, uint64_t value);
120 CVMX_FUNCTION void cvmx_write64_int32(uint64_t address, int32_t value);
121 CVMX_FUNCTION void cvmx_write64_uint32(uint64_t address, uint32_t value);
122 CVMX_FUNCTION void cvmx_write64_int16(uint64_t address, int16_t value);
123 CVMX_FUNCTION void cvmx_write64_uint16(uint64_t address, uint16_t value);
124 CVMX_FUNCTION void cvmx_write64_int8(uint64_t address, int8_t value);
125 CVMX_FUNCTION void cvmx_write64_uint8(uint64_t address, uint8_t value);
126 CVMX_FUNCTION void cvmx_write_csr(uint64_t csr_addr, uint64_t val);
127 CVMX_FUNCTION void cvmx_write_io(uint64_t io_addr, uint64_t val);
129 CVMX_FUNCTION int64_t cvmx_read64_int64(uint64_t address);
130 CVMX_FUNCTION uint64_t cvmx_read64_uint64(uint64_t address);
131 CVMX_FUNCTION int32_t cvmx_read64_int32(uint64_t address);
132 CVMX_FUNCTION uint32_t cvmx_read64_uint32(uint64_t address);
133 CVMX_FUNCTION int16_t cvmx_read64_int16(uint64_t address);
134 CVMX_FUNCTION uint16_t cvmx_read64_uint16(uint64_t address);
135 CVMX_FUNCTION int8_t cvmx_read64_int8(uint64_t address);
136 CVMX_FUNCTION uint8_t cvmx_read64_uint8(uint64_t address);
137 CVMX_FUNCTION uint64_t cvmx_read_csr(uint64_t csr_addr);
139 CVMX_FUNCTION void cvmx_send_single(uint64_t data);
140 CVMX_FUNCTION void cvmx_read_csr_async(uint64_t scraddr, uint64_t csr_addr);
143 * Number of the Core on which the program is currently running.
145 * @return Number of cores
147 CVMX_FUNCTION unsigned int cvmx_get_core_num(void);
150 * Returns the number of bits set in the provided value.
151 * Simple wrapper for POP instruction.
153 * @param val 32 bit value to count set bits in
155 * @return Number of bits set
157 CVMX_FUNCTION uint32_t cvmx_pop(uint32_t val);
160 * Returns the number of bits set in the provided value.
161 * Simple wrapper for DPOP instruction.
163 * @param val 64 bit value to count set bits in
165 * @return Number of bits set
167 CVMX_FUNCTION int cvmx_dpop(uint64_t val);
171 * Provide current cycle counter as a return value. Deprecated, use
172 * cvmx_clock_get_count(CVMX_CLOCK_CORE) to get cycle counter.
174 * @return current cycle counter
176 CVMX_FUNCTION uint64_t cvmx_get_cycle(void);
180 * Reads a chip global cycle counter. This counts SCLK cycles since
181 * chip reset. The counter is 64 bit. This function is deprecated as the rate
182 * of the global cycle counter is different between Octeon+ and Octeon2, use
183 * cvmx_clock_get_count(CVMX_CLOCK_SCLK) instead. For Octeon2, the clock rate
184 * of SCLK may be differnet than the core clock.
186 * @return Global chip cycle count since chip reset.
188 CVMX_FUNCTION uint64_t cvmx_get_cycle_global(void) __attribute__((deprecated));
191 * Wait for the specified number of core clock cycles
195 CVMX_FUNCTION void cvmx_wait(uint64_t cycles);
198 * Wait for the specified number of micro seconds
200 * @param usec micro seconds to wait
202 CVMX_FUNCTION void cvmx_wait_usec(uint64_t usec);
205 * Wait for the specified number of io clock cycles
209 CVMX_FUNCTION void cvmx_wait_io(uint64_t cycles);
212 * Perform a soft reset of Octeon
216 CVMX_FUNCTION void cvmx_reset_octeon(void);
219 * Read a byte of fuse data
220 * @param byte_addr address to read
222 * @return fuse value: 0 or 1
224 CVMX_FUNCTION uint8_t cvmx_fuse_read_byte(int byte_addr);
227 * Read a single fuse bit
229 * @param fuse Fuse number (0-1024)
231 * @return fuse value: 0 or 1
233 CVMX_FUNCTION int cvmx_fuse_read(int fuse);
241 #endif /* __CVMX_ACCESS_H__ */