cvmx-coremask.h revision 210284
12370SN/A/***********************license start***************
22685SN/A *  Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
32370SN/A *  reserved.
42370SN/A *
52370SN/A *
62370SN/A *  Redistribution and use in source and binary forms, with or without
72685SN/A *  modification, are permitted provided that the following conditions are
82370SN/A *  met:
92685SN/A *
102370SN/A *      * Redistributions of source code must retain the above copyright
112370SN/A *        notice, this list of conditions and the following disclaimer.
122370SN/A *
132370SN/A *      * Redistributions in binary form must reproduce the above
142370SN/A *        copyright notice, this list of conditions and the following
152370SN/A *        disclaimer in the documentation and/or other materials provided
162370SN/A *        with the distribution.
172370SN/A *
182370SN/A *      * Neither the name of Cavium Networks nor the names of
192370SN/A *        its contributors may be used to endorse or promote products
202370SN/A *        derived from this software without specific prior written
212685SN/A *        permission.
222685SN/A *
232685SN/A *  TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
242370SN/A *  AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
252370SN/A *  OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
262370SN/A *  RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
272370SN/A *  REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
282370SN/A *  DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
292370SN/A *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
302370SN/A *  PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
312370SN/A *  POSSESSION OR CORRESPONDENCE TO DESCRIPTION.  THE ENTIRE RISK ARISING OUT
322370SN/A *  OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
332370SN/A *
342370SN/A *
352370SN/A *  For any questions regarding licensing please contact marketing@caviumnetworks.com
362370SN/A *
372370SN/A ***********************license end**************************************/
382370SN/A
392370SN/A
402370SN/A
412370SN/A
422370SN/A
432370SN/A
442370SN/A/**
452370SN/A * @file
462370SN/A *
472370SN/A * Module to support operations on bitmap of cores. Coremask can be used to
482370SN/A * select a specific core, a group of cores, or all available cores, for
492370SN/A * initialization and differentiation of roles within a single shared binary
502370SN/A * executable image.
512370SN/A *
522370SN/A * <hr>$Revision: 41586 $<hr>
532370SN/A *
542370SN/A */
552370SN/A
562370SN/A
572370SN/A#ifndef __CVMX_COREMASK_H__
582370SN/A#define __CVMX_COREMASK_H__
592370SN/A
602370SN/A#include "cvmx-asm.h"
612370SN/A
622370SN/A#ifdef	__cplusplus
632370SN/Aextern "C" {
642370SN/A#endif
652370SN/A
662370SN/A/*
672370SN/A * coremask is simply unsigned int (32 bits).
682370SN/A *
692370SN/A * NOTE: supports up to 32 cores maximum.
702370SN/A *
712370SN/A * union of coremasks is simply bitwise-or.
722370SN/A * intersection of coremasks is simply bitwise-and.
732370SN/A *
742370SN/A */
752370SN/A
762370SN/A#define  CVMX_COREMASK_MAX  0xFFFFFFFFu    /* maximum supported mask */
772370SN/A
782370SN/A
792370SN/A/**
802370SN/A * Compute coremask for a specific core.
812370SN/A *
822370SN/A * @param  core_id  The core ID
832370SN/A *
842370SN/A * @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