1210284Sjmallett/***********************license start***************
2215990Sjmallett * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3215990Sjmallett * reserved.
4210284Sjmallett *
5210284Sjmallett *
6215990Sjmallett * Redistribution and use in source and binary forms, with or without
7215990Sjmallett * modification, are permitted provided that the following conditions are
8215990Sjmallett * met:
9210284Sjmallett *
10215990Sjmallett *   * Redistributions of source code must retain the above copyright
11215990Sjmallett *     notice, this list of conditions and the following disclaimer.
12210284Sjmallett *
13215990Sjmallett *   * Redistributions in binary form must reproduce the above
14215990Sjmallett *     copyright notice, this list of conditions and the following
15215990Sjmallett *     disclaimer in the documentation and/or other materials provided
16215990Sjmallett *     with the distribution.
17215990Sjmallett
18215990Sjmallett *   * Neither the name of Cavium Networks nor the names of
19215990Sjmallett *     its contributors may be used to endorse or promote products
20215990Sjmallett *     derived from this software without specific prior written
21215990Sjmallett *     permission.
22215990Sjmallett
23215990Sjmallett * This Software, including technical data, may be subject to U.S. export  control
24215990Sjmallett * laws, including the U.S. Export Administration Act and its  associated
25215990Sjmallett * regulations, and may be subject to export or import  regulations in other
26215990Sjmallett * countries.
27215990Sjmallett
28215990Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29215990Sjmallett * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30215990Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31215990Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32215990Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33215990Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34215990Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35215990Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36215990Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37215990Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38210284Sjmallett ***********************license end**************************************/
39210284Sjmallett
40210284Sjmallett
41210284Sjmallett
42210284Sjmallett
43210284Sjmallett
44210284Sjmallett
45215990Sjmallett
46210284Sjmallett/**
47210284Sjmallett * @file
48210284Sjmallett *
49210284Sjmallett * Module to support operations on bitmap of cores. Coremask can be used to
50210284Sjmallett * select a specific core, a group of cores, or all available cores, for
51210284Sjmallett * initialization and differentiation of roles within a single shared binary
52210284Sjmallett * executable image.
53210284Sjmallett *
54215990Sjmallett * <hr>$Revision: 49448 $<hr>
55210284Sjmallett *
56210284Sjmallett */
57210284Sjmallett
58210284Sjmallett
59210284Sjmallett#ifndef __CVMX_COREMASK_H__
60210284Sjmallett#define __CVMX_COREMASK_H__
61210284Sjmallett
62210284Sjmallett#include "cvmx-asm.h"
63210284Sjmallett
64210284Sjmallett#ifdef	__cplusplus
65210284Sjmallettextern "C" {
66210284Sjmallett#endif
67210284Sjmallett
68210284Sjmallett/*
69210284Sjmallett * coremask is simply unsigned int (32 bits).
70210284Sjmallett *
71210284Sjmallett * NOTE: supports up to 32 cores maximum.
72210284Sjmallett *
73210284Sjmallett * union of coremasks is simply bitwise-or.
74210284Sjmallett * intersection of coremasks is simply bitwise-and.
75210284Sjmallett *
76210284Sjmallett */
77210284Sjmallett
78210284Sjmallett#define  CVMX_COREMASK_MAX  0xFFFFFFFFu    /* maximum supported mask */
79210284Sjmallett
80210284Sjmallett
81210284Sjmallett/**
82210284Sjmallett * Compute coremask for a specific core.
83210284Sjmallett *
84210284Sjmallett * @param  core_id  The core ID
85210284Sjmallett *
86210284Sjmallett * @return  coremask for a specific core
87210284Sjmallett *
88210284Sjmallett */
89210284Sjmallettstatic inline unsigned int cvmx_coremask_core(unsigned int core_id)
90210284Sjmallett{
91210284Sjmallett    return (1u << core_id);
92210284Sjmallett}
93210284Sjmallett
94210284Sjmallett/**
95210284Sjmallett * Compute coremask for num_cores cores starting with core 0.
96210284Sjmallett *
97210284Sjmallett * @param  num_cores  number of cores
98210284Sjmallett *
99210284Sjmallett * @return  coremask for num_cores cores
100210284Sjmallett *
101210284Sjmallett */
102210284Sjmallettstatic inline unsigned int cvmx_coremask_numcores(unsigned int num_cores)
103210284Sjmallett{
104210284Sjmallett    return (CVMX_COREMASK_MAX >> (32 - num_cores));
105210284Sjmallett}
106210284Sjmallett
107210284Sjmallett/**
108210284Sjmallett * Compute coremask for a range of cores from core low to core high.
109210284Sjmallett *
110210284Sjmallett * @param  low   first core in the range
111210284Sjmallett * @param  high  last core in the range
112210284Sjmallett *
113210284Sjmallett * @return  coremask for the range of cores
114210284Sjmallett *
115210284Sjmallett */
116210284Sjmallettstatic inline unsigned int cvmx_coremask_range(unsigned int low, unsigned int high)
117210284Sjmallett{
118210284Sjmallett    return ((CVMX_COREMASK_MAX >> (31 - high + low)) << low);
119210284Sjmallett}
120210284Sjmallett
121210284Sjmallett
122210284Sjmallett/**
123210284Sjmallett * Test to see if current core is a member of coremask.
124210284Sjmallett *
125210284Sjmallett * @param  coremask  the coremask to test against
126210284Sjmallett *
127210284Sjmallett * @return  1 if current core is a member of coremask, 0 otherwise
128210284Sjmallett *
129210284Sjmallett */
130210284Sjmallettstatic inline int cvmx_coremask_is_member(unsigned int coremask)
131210284Sjmallett{
132210284Sjmallett    return ((cvmx_coremask_core(cvmx_get_core_num()) & coremask) != 0);
133210284Sjmallett}
134210284Sjmallett
135210284Sjmallett/**
136210284Sjmallett * Test to see if current core is first core in coremask.
137210284Sjmallett *
138210284Sjmallett * @param  coremask  the coremask to test against
139210284Sjmallett *
140210284Sjmallett * @return  1 if current core is first core in the coremask, 0 otherwise
141210284Sjmallett *
142210284Sjmallett */
143210284Sjmallettstatic inline int cvmx_coremask_first_core(unsigned int coremask)
144210284Sjmallett{
145210284Sjmallett    return cvmx_coremask_is_member(coremask)
146210284Sjmallett        && ((cvmx_get_core_num() == 0) ||
147210284Sjmallett            ((cvmx_coremask_numcores(cvmx_get_core_num()) & coremask) == 0));
148210284Sjmallett}
149210284Sjmallett
150210284Sjmallett/**
151210284Sjmallett * Wait (stall) until all cores in the given coremask has reached this point
152210284Sjmallett * in the program execution before proceeding.
153210284Sjmallett *
154210284Sjmallett * @param  coremask  the group of cores performing the barrier sync
155210284Sjmallett *
156210284Sjmallett */
157210284Sjmallettextern void cvmx_coremask_barrier_sync(unsigned int coremask);
158210284Sjmallett
159210284Sjmallett#ifdef	__cplusplus
160210284Sjmallett}
161210284Sjmallett#endif
162210284Sjmallett
163210284Sjmallett#endif /* __CVMX_COREMASK_H__ */
164