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**************************************/
49 * This file is resposible for including all system dependent
50 * headers for the cvmx-* files.
52 * <hr>$Revision: 70030 $<hr>
55 #ifndef __CVMX_PLATFORM_H__
56 #define __CVMX_PLATFORM_H__
61 #define EXTERN_ASM extern "C"
63 #define EXTERN_ASM extern
66 /* This file defines macros for use in determining the current
67 building environment. It defines a single CVMX_BUILD_FOR_*
68 macro representing the target of the build. The current
71 CVMX_BUILD_FOR_LINUX_KERNEL
72 CVMX_BUILD_FOR_LINUX_USER
73 CVMX_BUILD_FOR_LINUX_HOST
74 CVMX_BUILD_FOR_VXWORKS
75 CVMX_BUILD_FOR_STANDALONE */
76 #if defined(__U_BOOT__)
77 /* We are being used inside of Uboot */
78 #define CVMX_BUILD_FOR_UBOOT
79 #elif defined(__linux__)
80 #if defined(__KERNEL__)
81 /* We are in the Linux kernel on Octeon */
82 #define CVMX_BUILD_FOR_LINUX_KERNEL
83 #elif !defined(__mips__)
84 /* We are being used under Linux but not on Octeon. Assume
85 we are on a Linux host with an Octeon target over PCI/PCIe */
86 #ifndef CVMX_BUILD_FOR_LINUX_HOST
87 #define CVMX_BUILD_FOR_LINUX_HOST
90 #ifdef CVMX_BUILD_FOR_LINUX_HOST
91 /* This is a manual special case. The host PCI utilities can
92 be configured to run on Octeon. In this case it is impossible
93 to tell the difference between the normal userspace setup
94 and using cvmx_read/write_csr over the PCI bus. The host
95 utilites force this define to fix this */
97 /* We are in the Linux userspace on Octeon */
98 #define CVMX_BUILD_FOR_LINUX_USER
101 #elif defined(_WRS_KERNEL) || defined(VXWORKS_USER_MAPPINGS)
102 /* We are in VxWorks on Octeon */
103 #define CVMX_BUILD_FOR_VXWORKS
104 #elif defined(_OCTEON_TOOLCHAIN_RUNTIME)
105 /* To build the simple exec toolchain runtime (newlib) library. We
106 should only use features available on all Octeon models. */
107 #define CVMX_BUILD_FOR_TOOLCHAIN
108 #elif defined(__FreeBSD__) && defined(_KERNEL)
109 #define CVMX_BUILD_FOR_FREEBSD_KERNEL
111 /* We are building a simple exec standalone image for Octeon */
112 #define CVMX_BUILD_FOR_STANDALONE
116 /* To have a global variable be shared among all cores,
117 * declare with the CVMX_SHARED attribute. Ex:
118 * CVMX_SHARED int myglobal;
119 * This will cause the variable to be placed in a special
120 * section that the loader will map as shared for all cores
121 * This is for data structures use by software ONLY,
122 * as it is not 1-1 VA-PA mapped.
124 #if defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
127 #ifndef CVMX_BUILD_FOR_LINUX_HOST
128 #define CVMX_SHARED __attribute__ ((cvmx_shared))
134 #if defined(CVMX_BUILD_FOR_UBOOT)
137 #include "cvmx-sysinfo.h"
139 #elif defined(CVMX_BUILD_FOR_LINUX_KERNEL)
141 #include <linux/kernel.h>
142 #include <linux/string.h>
143 #include <linux/types.h>
146 #elif defined(CVMX_BUILD_FOR_LINUX_USER)
156 #include <sys/mman.h>
159 #include <sys/sysmips.h>
160 #define MIPS_CAVIUM_XKPHYS_READ 2010 /* XKPHYS */
161 #define MIPS_CAVIUM_XKPHYS_WRITE 2011 /* XKPHYS */
163 /* Enable access to XKPHYS segments. Warning message is printed in case of
164 error. If warn_count is set, the warning message is not displayed. */
165 static inline void cvmx_linux_enable_xkphys_access(int32_t warn_count)
168 ret = sysmips(MIPS_CAVIUM_XKPHYS_WRITE, getpid(), 3, 0);
169 if (ret != 0 && !warn_count) {
172 perror("sysmips(MIPS_CAVIUM_XKPHYS_WRITE) failed.\n"
173 " Did you configure your kernel with both:\n"
174 " CONFIG_CAVIUM_OCTEON_USER_MEM_PER_PROCESS *and*\n"
175 " CONFIG_CAVIUM_OCTEON_USER_IO_PER_PROCESS?");
178 perror("sysmips(MIPS_CAVIUM_XKPHYS_WRITE) failed.\n"
179 " Are you running as root?");
182 perror("sysmips(MIPS_CAVIUM_XKPHYS_WRITE) failed");
188 #elif defined(CVMX_BUILD_FOR_LINUX_HOST)
198 #include <sys/mman.h>
201 #elif defined(CVMX_BUILD_FOR_VXWORKS)
210 #elif defined(CVMX_BUILD_FOR_STANDALONE)
220 #elif defined(CVMX_BUILD_FOR_TOOLCHAIN)
231 #include "rename-cvmx.h"
233 #elif defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
235 #include <mips/cavium/cvmx_config.h>
239 #error Unexpected CVMX_BUILD_FOR_* macro
243 #endif /* __CVMX_PLATFORM_H__ */