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