1 /***********************license start***************
2 * Copyright (c) 2003-2010 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 * 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 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**************************************/
49 * Module to support operations on bitmap of cores. Coremask can be used to
50 * select a specific core, a group of cores, or all available cores, for
51 * initialization and differentiation of roles within a single shared binary
54 * <hr>$Revision: 49448 $<hr>
59 #ifndef __CVMX_COREMASK_H__
60 #define __CVMX_COREMASK_H__
69 * coremask is simply unsigned int (32 bits).
71 * NOTE: supports up to 32 cores maximum.
73 * union of coremasks is simply bitwise-or.
74 * intersection of coremasks is simply bitwise-and.
78 #define CVMX_COREMASK_MAX 0xFFFFFFFFu /* maximum supported mask */
82 * Compute coremask for a specific core.
84 * @param core_id The core ID
86 * @return coremask for a specific core
89 static inline unsigned int cvmx_coremask_core(unsigned int core_id)
91 return (1u << core_id);
95 * Compute coremask for num_cores cores starting with core 0.
97 * @param num_cores number of cores
99 * @return coremask for num_cores cores
102 static inline unsigned int cvmx_coremask_numcores(unsigned int num_cores)
104 return (CVMX_COREMASK_MAX >> (32 - num_cores));
108 * Compute coremask for a range of cores from core low to core high.
110 * @param low first core in the range
111 * @param high last core in the range
113 * @return coremask for the range of cores
116 static inline unsigned int cvmx_coremask_range(unsigned int low, unsigned int high)
118 return ((CVMX_COREMASK_MAX >> (31 - high + low)) << low);
123 * Test to see if current core is a member of coremask.
125 * @param coremask the coremask to test against
127 * @return 1 if current core is a member of coremask, 0 otherwise
130 static inline int cvmx_coremask_is_member(unsigned int coremask)
132 return ((cvmx_coremask_core(cvmx_get_core_num()) & coremask) != 0);
136 * Test to see if current core is first core in coremask.
138 * @param coremask the coremask to test against
140 * @return 1 if current core is first core in the coremask, 0 otherwise
143 static inline int cvmx_coremask_first_core(unsigned int coremask)
145 return cvmx_coremask_is_member(coremask)
146 && ((cvmx_get_core_num() == 0) ||
147 ((cvmx_coremask_numcores(cvmx_get_core_num()) & coremask) == 0));
151 * Wait (stall) until all cores in the given coremask has reached this point
152 * in the program execution before proceeding.
154 * @param coremask the group of cores performing the barrier sync
157 extern void cvmx_coremask_barrier_sync(unsigned int coremask);
163 #endif /* __CVMX_COREMASK_H__ */