]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-platform.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / cvmx-platform.h
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
43
44
45
46 /**
47  * @file
48  *
49  * This file is resposible for including all system dependent
50  * headers for the cvmx-* files.
51  *
52  * <hr>$Revision: 49448 $<hr>
53 */
54
55 #ifndef __CVMX_PLATFORM_H__
56 #define __CVMX_PLATFORM_H__
57
58 #include "cvmx-abi.h"
59
60 #ifdef __cplusplus
61 #define EXTERN_ASM extern "C"
62 #else
63 #define EXTERN_ASM extern
64 #endif
65
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
69     possibilities are:
70         CVMX_BUILD_FOR_UBOOT
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
88         #endif
89     #else
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 */
96         #else
97             /* We are in the Linux userspace on Octeon */
98             #define CVMX_BUILD_FOR_LINUX_USER
99         #endif
100     #endif
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
110 #else
111     /* We are building a simple exec standalone image for Octeon */
112     #define CVMX_BUILD_FOR_STANDALONE
113 #endif
114
115
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.
123  */
124 #if defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
125 #define CVMX_SHARED
126 #else
127 #ifndef CVMX_BUILD_FOR_LINUX_HOST
128 #define CVMX_SHARED __attribute__ ((cvmx_shared))
129 #else
130 #define CVMX_SHARED
131 #endif
132 #endif
133
134 #if defined(CVMX_BUILD_FOR_UBOOT)
135
136     #include <common.h>
137     #include "cvmx-sysinfo.h"
138
139 #elif defined(CVMX_BUILD_FOR_LINUX_KERNEL)
140
141     #include <linux/kernel.h>
142     #include <linux/string.h>
143     #include <linux/types.h>
144     #include <stdarg.h>
145
146 #elif defined(CVMX_BUILD_FOR_LINUX_USER)
147
148     #include <stddef.h>
149     #include <stdint.h>
150     #include <stdio.h>
151     #include <stdlib.h>
152     #include <stdarg.h>
153     #include <string.h>
154     #include <assert.h>
155     #include <fcntl.h>
156     #include <sys/mman.h>
157     #include <unistd.h>
158     #include <errno.h>
159     #include <sys/sysmips.h>
160     #define MIPS_CAVIUM_XKPHYS_READ        2010 /* XKPHYS */
161     #define MIPS_CAVIUM_XKPHYS_WRITE       2011 /* XKPHYS */
162
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)
166 {
167     int ret;
168     ret = sysmips(MIPS_CAVIUM_XKPHYS_WRITE, getpid(), 3, 0);
169     if (ret != 0 && !warn_count) {
170         switch(errno) {
171             case EINVAL:
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?");
176                 break;
177             case EPERM:
178                 perror("sysmips(MIPS_CAVIUM_XKPHYS_WRITE) failed.\n"
179                      "  Are you running as root?");
180                 break;
181             default:
182                 perror("sysmips(MIPS_CAVIUM_XKPHYS_WRITE) failed");
183                 break;
184         }
185     }
186 }
187
188 #elif defined(CVMX_BUILD_FOR_LINUX_HOST)
189
190     #include <stddef.h>
191     #include <stdint.h>
192     #include <stdio.h>
193     #include <stdlib.h>
194     #include <stdarg.h>
195     #include <string.h>
196     #include <assert.h>
197     #include <fcntl.h>
198     #include <sys/mman.h>
199     #include <unistd.h>
200
201 #elif defined(CVMX_BUILD_FOR_VXWORKS)
202
203     #include <stdint.h>
204     #include <stdio.h>
205     #include <stdlib.h>
206     #include <stdarg.h>
207     #include <string.h>
208     #include <assert.h>
209
210 #elif defined(CVMX_BUILD_FOR_STANDALONE)
211
212     #include <stddef.h>
213     #include <stdint.h>
214     #include <stdio.h>
215     #include <stdlib.h>
216     #include <stdarg.h>
217     #include <string.h>
218     #include <assert.h>
219
220 #elif defined(CVMX_BUILD_FOR_TOOLCHAIN)
221
222     #include <stddef.h>
223     #include <stdint.h>
224     #include <stdio.h>
225     #include <stdlib.h>
226     #include <stdarg.h>
227     #include <string.h>
228     #include <assert.h>
229
230 #elif defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
231
232     #include <mips/cavium/cvmx_config.h>
233
234 #else
235
236     #error Unexpected CVMX_BUILD_FOR_* macro
237
238 #endif
239
240 #endif /* __CVMX_PLATFORM_H__ */