1 /***********************license start***************
2 * Copyright (c) 2003-2008 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**************************************/
47 * Module to support operations on bitmap of cores. Coremask can be used to
48 * select a specific core, a group of cores, or all available cores, for
49 * initialization and differentiation of roles within a single shared binary
52 * <hr>$Revision: 41586 $<hr>
57 #ifndef __CVMX_COREMASK_H__
58 #define __CVMX_COREMASK_H__
67 * coremask is simply unsigned int (32 bits).
69 * NOTE: supports up to 32 cores maximum.
71 * union of coremasks is simply bitwise-or.
72 * intersection of coremasks is simply bitwise-and.
76 #define CVMX_COREMASK_MAX 0xFFFFFFFFu /* maximum supported mask */
80 * Compute coremask for a specific core.
82 * @param core_id The core ID
84 * @return coremask for a specific core
87 static inline unsigned int cvmx_coremask_core(unsigned int core_id)
89 return (1u << core_id);
93 * Compute coremask for num_cores cores starting with core 0.
95 * @param num_cores number of cores
97 * @return coremask for num_cores cores
100 static inline unsigned int cvmx_coremask_numcores(unsigned int num_cores)
102 return (CVMX_COREMASK_MAX >> (32 - num_cores));
106 * Compute coremask for a range of cores from core low to core high.
108 * @param low first core in the range
109 * @param high last core in the range
111 * @return coremask for the range of cores
114 static inline unsigned int cvmx_coremask_range(unsigned int low, unsigned int high)
116 return ((CVMX_COREMASK_MAX >> (31 - high + low)) << low);
121 * Test to see if current core is a member of coremask.
123 * @param coremask the coremask to test against
125 * @return 1 if current core is a member of coremask, 0 otherwise
128 static inline int cvmx_coremask_is_member(unsigned int coremask)
130 return ((cvmx_coremask_core(cvmx_get_core_num()) & coremask) != 0);
134 * Test to see if current core is first core in coremask.
136 * @param coremask the coremask to test against
138 * @return 1 if current core is first core in the coremask, 0 otherwise
141 static inline int cvmx_coremask_first_core(unsigned int coremask)
143 return cvmx_coremask_is_member(coremask)
144 && ((cvmx_get_core_num() == 0) ||
145 ((cvmx_coremask_numcores(cvmx_get_core_num()) & coremask) == 0));
149 * Wait (stall) until all cores in the given coremask has reached this point
150 * in the program execution before proceeding.
152 * @param coremask the group of cores performing the barrier sync
155 extern void cvmx_coremask_barrier_sync(unsigned int coremask);
161 #endif /* __CVMX_COREMASK_H__ */