1 /***********************license start***************
2 * Copyright (c) 2003-2009 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
41 * Function prototypes for accessing memory and CSRs on Octeon.
43 * <hr>$Revision: 38306 $<hr>
45 #ifndef __CVMX_ACCESS_H__
46 #define __CVMX_ACCESS_H__
52 /* We're going to assume that if we are compiling for Mips then we must be
53 running natively on Octoen. It is possible that this code could be
54 compiled on a non Octeon Mips that is acting as a PCI/PCIe host. In this
55 case this assumption will be wrong and cause issues We can't key off of
56 __octeon__ since some people use stock gcc toolchains */
57 #if defined(__mips__) && !defined(CVMX_BUILD_FOR_LINUX_HOST)
58 #define CVMX_FUNCTION static inline
60 #define CVMX_FUNCTION extern
64 * simprintf uses simulator tricks to speed up printouts. The format
65 * and args are passed to the simulator and processed natively on the host.
66 * Simprintf is limited to 7 arguments, and they all must use %ll (long long)
67 * format specifiers to be displayed correctly.
73 EXTERN_ASM void simprintf(const char *format, ...);
76 * This function performs some default initialization of the Octeon executive.
77 * It initializes the cvmx_bootmem memory allocator with the list of physical
78 * memory provided by the bootloader, and creates 1-1 TLB mappings for this
79 * memory. This function should be called on all cores that will use either the
80 * bootmem allocator or the 1-1 TLB mappings. Applications which require a
81 * different configuration can replace this function with a suitable application
84 * @return 0 on success
87 extern int cvmx_user_app_init(void);
90 * Returns the Octeon processor ID.
92 * @return Octeon processor ID from COP0
94 CVMX_FUNCTION uint32_t cvmx_get_proc_id(void) __attribute__ ((pure));
97 * Convert a memory pointer (void*) into a hardware compatable
98 * memory address (uint64_t). Octeon hardware widgets don't
99 * understand logical addresses.
101 * @param ptr C style memory pointer
102 * @return Hardware physical address
104 CVMX_FUNCTION uint64_t cvmx_ptr_to_phys(void *ptr);
107 * Convert a hardware physical address (uint64_t) into a
108 * memory pointer (void *).
110 * @param physical_address
111 * Hardware physical address to memory
112 * @return Pointer to memory
114 CVMX_FUNCTION void *cvmx_phys_to_ptr(uint64_t physical_address);
116 CVMX_FUNCTION void cvmx_write64_int64(uint64_t address, int64_t value);
117 CVMX_FUNCTION void cvmx_write64_uint64(uint64_t address, uint64_t value);
118 CVMX_FUNCTION void cvmx_write64_int32(uint64_t address, int32_t value);
119 CVMX_FUNCTION void cvmx_write64_uint32(uint64_t address, uint32_t value);
120 CVMX_FUNCTION void cvmx_write64_int16(uint64_t address, int16_t value);
121 CVMX_FUNCTION void cvmx_write64_uint16(uint64_t address, uint16_t value);
122 CVMX_FUNCTION void cvmx_write64_int8(uint64_t address, int8_t value);
123 CVMX_FUNCTION void cvmx_write64_uint8(uint64_t address, uint8_t value);
124 CVMX_FUNCTION void cvmx_write_csr(uint64_t csr_addr, uint64_t val);
125 CVMX_FUNCTION void cvmx_write_io(uint64_t io_addr, uint64_t val);
127 CVMX_FUNCTION int64_t cvmx_read64_int64(uint64_t address);
128 CVMX_FUNCTION uint64_t cvmx_read64_uint64(uint64_t address);
129 CVMX_FUNCTION int32_t cvmx_read64_int32(uint64_t address);
130 CVMX_FUNCTION uint32_t cvmx_read64_uint32(uint64_t address);
131 CVMX_FUNCTION int16_t cvmx_read64_int16(uint64_t address);
132 CVMX_FUNCTION uint16_t cvmx_read64_uint16(uint64_t address);
133 CVMX_FUNCTION int8_t cvmx_read64_int8(uint64_t address);
134 CVMX_FUNCTION uint8_t cvmx_read64_uint8(uint64_t address);
135 CVMX_FUNCTION uint64_t cvmx_read_csr(uint64_t csr_addr);
137 CVMX_FUNCTION void cvmx_send_single(uint64_t data);
138 CVMX_FUNCTION void cvmx_read_csr_async(uint64_t scraddr, uint64_t csr_addr);
141 * Number of the Core on which the program is currently running.
143 * @return Number of cores
145 CVMX_FUNCTION unsigned int cvmx_get_core_num(void);
148 * Returns the number of bits set in the provided value.
149 * Simple wrapper for POP instruction.
151 * @param val 32 bit value to count set bits in
153 * @return Number of bits set
155 CVMX_FUNCTION uint32_t cvmx_pop(uint32_t val);
158 * Returns the number of bits set in the provided value.
159 * Simple wrapper for DPOP instruction.
161 * @param val 64 bit value to count set bits in
163 * @return Number of bits set
165 CVMX_FUNCTION int cvmx_dpop(uint64_t val);
168 * Provide current cycle counter as a return value
170 * @return current cycle counter
172 CVMX_FUNCTION uint64_t cvmx_get_cycle(void);
175 * Reads a chip global cycle counter. This counts CPU cycles since
176 * chip reset. The counter is 64 bit.
177 * This register does not exist on CN38XX pass 1 silicion
179 * @return Global chip cycle count since chip reset.
181 CVMX_FUNCTION uint64_t cvmx_get_cycle_global(void);
184 * Wait for the specified number of cycle
188 CVMX_FUNCTION void cvmx_wait(uint64_t cycles);
191 * Wait for the specified number of micro seconds
193 * @param usec micro seconds to wait
195 CVMX_FUNCTION void cvmx_wait_usec(uint64_t usec);
198 * Perform a soft reset of Octeon
202 CVMX_FUNCTION void cvmx_reset_octeon(void);
205 * Read a byte of fuse data
206 * @param byte_addr address to read
208 * @return fuse value: 0 or 1
210 CVMX_FUNCTION uint8_t cvmx_fuse_read_byte(int byte_addr);
213 * Read a single fuse bit
215 * @param fuse Fuse number (0-1024)
217 * @return fuse value: 0 or 1
219 CVMX_FUNCTION int cvmx_fuse_read(int fuse);
227 #endif /* __CVMX_ACCESS_H__ */