1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (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 Inc. 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 * 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
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. 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**************************************/
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
54 * <hr>$Revision: 70030 $<hr>
58 #include "cvmx-config.h"
60 #include "cvmx-spinlock.h"
61 #include "cvmx-coremask.h"
64 #define CVMX_COREMASK_MAX_SYNCS 20 /* maximum number of coremasks for barrier sync */
67 * This structure defines the private state maintained by coremask module.
70 CVMX_SHARED static struct {
72 cvmx_spinlock_t lock; /**< mutex spinlock */
76 unsigned int coremask; /**< coremask specified for barrier */
77 unsigned int checkin; /**< bitmask of cores checking in */
78 volatile unsigned int exit; /**< variable to poll for exit condition */
80 } s[CVMX_COREMASK_MAX_SYNCS];
84 { CVMX_SPINLOCK_UNLOCKED_VAL },
91 * Wait (stall) until all cores in the given coremask has reached this point
92 * in the program execution before proceeding.
94 * @param coremask the group of cores performing the barrier sync
97 void cvmx_coremask_barrier_sync(unsigned int coremask)
102 assert(coremask != 0);
104 cvmx_spinlock_lock(&state.lock);
106 for (i = 0; i < CVMX_COREMASK_MAX_SYNCS; i++) {
108 if (state.s[i].coremask == 0) {
109 /* end of existing coremask list, create new entry, fall-thru */
110 state.s[i].coremask = coremask;
113 if (state.s[i].coremask == coremask) {
115 target = state.s[i].exit + 1; /* wrap-around at 32b */
117 state.s[i].checkin |= cvmx_coremask_core(cvmx_get_core_num());
118 if (state.s[i].checkin == coremask) {
119 state.s[i].checkin = 0;
120 state.s[i].exit = target; /* signal exit condition */
122 cvmx_spinlock_unlock(&state.lock);
124 while (state.s[i].exit != target)
131 /* error condition - coremask array overflowed */
132 cvmx_spinlock_unlock(&state.lock);