cvmx-platform.h revision 232812
1103196Smike/***********************license start***************
233236Sjdp * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
333236Sjdp * reserved.
433236Sjdp *
533236Sjdp *
633236Sjdp * Redistribution and use in source and binary forms, with or without
733236Sjdp * modification, are permitted provided that the following conditions are
833236Sjdp * met:
933236Sjdp *
1033236Sjdp *   * Redistributions of source code must retain the above copyright
1133236Sjdp *     notice, this list of conditions and the following disclaimer.
1233236Sjdp *
1333236Sjdp *   * Redistributions in binary form must reproduce the above
1433236Sjdp *     copyright notice, this list of conditions and the following
1533236Sjdp *     disclaimer in the documentation and/or other materials provided
1633236Sjdp *     with the distribution.
1733236Sjdp
1833236Sjdp *   * Neither the name of Cavium Inc. nor the names of
1933236Sjdp *     its contributors may be used to endorse or promote products
2033236Sjdp *     derived from this software without specific prior written
2133236Sjdp *     permission.
2233236Sjdp
2333236Sjdp * This Software, including technical data, may be subject to U.S. export  control
2433236Sjdp * laws, including the U.S. Export Administration Act and its  associated
2533236Sjdp * regulations, and may be subject to export or import  regulations in other
2633236Sjdp * countries.
2733236Sjdp
2833236Sjdp * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
2933236Sjdp * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
3033236Sjdp * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
3133236Sjdp * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
3233236Sjdp * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
3350473Speter * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
3433236Sjdp * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
3533236Sjdp * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
3633236Sjdp * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
3733236Sjdp * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38103196Smike ***********************license end**************************************/
39110804Skan
4033236Sjdp
4133236Sjdp
4250603Sjdp
4333236Sjdp
44103196Smike
45103196Smike
46103196Smike/**
47103196Smike * @file
48103196Smike *
49103196Smike * This file is resposible for including all system dependent
5033236Sjdp * headers for the cvmx-* files.
5133236Sjdp *
52110804Skan * <hr>$Revision: 70030 $<hr>
5333236Sjdp*/
54110804Skan
55110804Skan#ifndef __CVMX_PLATFORM_H__
56110804Skan#define __CVMX_PLATFORM_H__
57110804Skan
58110804Skan#include "cvmx-abi.h"
59110804Skan
60110804Skan#ifdef __cplusplus
61110804Skan#define EXTERN_ASM extern "C"
62110804Skan#else
63103196Smike#define EXTERN_ASM extern
64103196Smike#endif
65110804Skan
6633236Sjdp/* This file defines macros for use in determining the current
67103212Smike    building environment. It defines a single CVMX_BUILD_FOR_*
68110804Skan    macro representing the target of the build. The current
69110804Skan    possibilities are:
70110804Skan        CVMX_BUILD_FOR_UBOOT
71110804Skan        CVMX_BUILD_FOR_LINUX_KERNEL
72110804Skan        CVMX_BUILD_FOR_LINUX_USER
73110804Skan        CVMX_BUILD_FOR_LINUX_HOST
7433236Sjdp        CVMX_BUILD_FOR_VXWORKS
7533236Sjdp        CVMX_BUILD_FOR_STANDALONE */
7633236Sjdp#if defined(__U_BOOT__)
77103196Smike    /* We are being used inside of Uboot */
78103196Smike    #define CVMX_BUILD_FOR_UBOOT
79103196Smike#elif defined(__linux__)
80103196Smike    #if defined(__KERNEL__)
81103196Smike        /* We are in the Linux kernel on Octeon */
8233236Sjdp        #define CVMX_BUILD_FOR_LINUX_KERNEL
8333236Sjdp    #elif !defined(__mips__)
84103196Smike        /* We are being used under Linux but not on Octeon. Assume
8597475Swollman            we are on a Linux host with an Octeon target over PCI/PCIe */
8697475Swollman        #ifndef CVMX_BUILD_FOR_LINUX_HOST
8797475Swollman        #define CVMX_BUILD_FOR_LINUX_HOST
8897475Swollman        #endif
8997475Swollman    #else
9097475Swollman        #ifdef CVMX_BUILD_FOR_LINUX_HOST
9197475Swollman            /* This is a manual special case. The host PCI utilities can
9297475Swollman                be configured to run on Octeon. In this case it is impossible
9397475Swollman                to tell the difference between the normal userspace setup
94103196Smike                and using cvmx_read/write_csr over the PCI bus. The host
9597475Swollman                utilites force this define to fix this */
9697475Swollman        #else
97103196Smike            /* We are in the Linux userspace on Octeon */
9897475Swollman            #define CVMX_BUILD_FOR_LINUX_USER
99110804Skan        #endif
100110804Skan    #endif
101110804Skan#elif defined(_WRS_KERNEL) || defined(VXWORKS_USER_MAPPINGS)
102110804Skan    /* We are in VxWorks on Octeon */
103110804Skan    #define CVMX_BUILD_FOR_VXWORKS
104110804Skan#elif defined(_OCTEON_TOOLCHAIN_RUNTIME)
105110804Skan    /* To build the simple exec toolchain runtime (newlib) library. We
106110804Skan       should only use features available on all Octeon models.  */
107110804Skan    #define CVMX_BUILD_FOR_TOOLCHAIN
108110804Skan#elif defined(__FreeBSD__) && defined(_KERNEL)
109110804Skan    #define CVMX_BUILD_FOR_FREEBSD_KERNEL
110110804Skan#else
111110804Skan    /* We are building a simple exec standalone image for Octeon */
112110804Skan    #define CVMX_BUILD_FOR_STANDALONE
113103212Smike#endif
114103212Smike
11533236Sjdp
116103196Smike/* To have a global variable be shared among all cores,
117103196Smike * declare with the CVMX_SHARED attribute.  Ex:
118103196Smike * CVMX_SHARED int myglobal;
119103196Smike * This will cause the variable to be placed in a special
120103196Smike * section that the loader will map as shared for all cores
121103212Smike * This is for data structures use by software ONLY,
12297475Swollman * as it is not 1-1 VA-PA mapped.
12397475Swollman */
124110804Skan#if defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
125103212Smike#define CVMX_SHARED
126110804Skan#else
127103196Smike#ifndef CVMX_BUILD_FOR_LINUX_HOST
128103196Smike#define CVMX_SHARED __attribute__ ((cvmx_shared))
129103196Smike#else
130103196Smike#define CVMX_SHARED
131103196Smike#endif
132103196Smike#endif
133103196Smike
134153515Skan#if defined(CVMX_BUILD_FOR_UBOOT)
135153515Skan
13697475Swollman    #include <common.h>
13733236Sjdp    #include "cvmx-sysinfo.h"
13833236Sjdp
13933236Sjdp#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. */
165static 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    #ifndef __ASSEMBLY__
223    #include <stddef.h>
224    #include <stdint.h>
225    #include <stdio.h>
226    #include <stdlib.h>
227    #include <stdarg.h>
228    #include <string.h>
229    #include <assert.h>
230    #endif
231    #include "rename-cvmx.h"
232
233#elif defined(CVMX_BUILD_FOR_FREEBSD_KERNEL)
234
235    #include <mips/cavium/cvmx_config.h>
236
237#else
238
239    #error Unexpected CVMX_BUILD_FOR_* macro
240
241#endif
242
243#endif /* __CVMX_PLATFORM_H__ */
244