]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-coremask.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-coremask.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  * 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
52  * executable image.
53  *
54  * <hr>$Revision: 49448 $<hr>
55  *
56  */
57
58
59 #ifndef __CVMX_COREMASK_H__
60 #define __CVMX_COREMASK_H__
61
62 #include "cvmx-asm.h"
63
64 #ifdef  __cplusplus
65 extern "C" {
66 #endif
67
68 /*
69  * coremask is simply unsigned int (32 bits).
70  *
71  * NOTE: supports up to 32 cores maximum.
72  *
73  * union of coremasks is simply bitwise-or.
74  * intersection of coremasks is simply bitwise-and.
75  *
76  */
77
78 #define  CVMX_COREMASK_MAX  0xFFFFFFFFu    /* maximum supported mask */
79
80
81 /**
82  * Compute coremask for a specific core.
83  *
84  * @param  core_id  The core ID
85  *
86  * @return  coremask for a specific core
87  *
88  */
89 static inline unsigned int cvmx_coremask_core(unsigned int core_id)
90 {
91     return (1u << core_id);
92 }
93
94 /**
95  * Compute coremask for num_cores cores starting with core 0.
96  *
97  * @param  num_cores  number of cores
98  *
99  * @return  coremask for num_cores cores
100  *
101  */
102 static inline unsigned int cvmx_coremask_numcores(unsigned int num_cores)
103 {
104     return (CVMX_COREMASK_MAX >> (32 - num_cores));
105 }
106
107 /**
108  * Compute coremask for a range of cores from core low to core high.
109  *
110  * @param  low   first core in the range
111  * @param  high  last core in the range
112  *
113  * @return  coremask for the range of cores
114  *
115  */
116 static inline unsigned int cvmx_coremask_range(unsigned int low, unsigned int high)
117 {
118     return ((CVMX_COREMASK_MAX >> (31 - high + low)) << low);
119 }
120
121
122 /**
123  * Test to see if current core is a member of coremask.
124  *
125  * @param  coremask  the coremask to test against
126  *
127  * @return  1 if current core is a member of coremask, 0 otherwise
128  *
129  */
130 static inline int cvmx_coremask_is_member(unsigned int coremask)
131 {
132     return ((cvmx_coremask_core(cvmx_get_core_num()) & coremask) != 0);
133 }
134
135 /**
136  * Test to see if current core is first core in coremask.
137  *
138  * @param  coremask  the coremask to test against
139  *
140  * @return  1 if current core is first core in the coremask, 0 otherwise
141  *
142  */
143 static inline int cvmx_coremask_first_core(unsigned int coremask)
144 {
145     return cvmx_coremask_is_member(coremask)
146         && ((cvmx_get_core_num() == 0) ||
147             ((cvmx_coremask_numcores(cvmx_get_core_num()) & coremask) == 0));
148 }
149
150 /**
151  * Wait (stall) until all cores in the given coremask has reached this point
152  * in the program execution before proceeding.
153  *
154  * @param  coremask  the group of cores performing the barrier sync
155  *
156  */
157 extern void cvmx_coremask_barrier_sync(unsigned int coremask);
158
159 #ifdef  __cplusplus
160 }
161 #endif
162
163 #endif /* __CVMX_COREMASK_H__ */