1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (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 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 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 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**************************************/ 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: 70030 $<hr> 55 * 56 */ 57 58#include "cvmx-config.h" 59#include "cvmx.h" 60#include "cvmx-spinlock.h" 61#include "cvmx-coremask.h" 62 63 64#define CVMX_COREMASK_MAX_SYNCS 20 /* maximum number of coremasks for barrier sync */ 65 66/** 67 * This structure defines the private state maintained by coremask module. 68 * 69 */ 70CVMX_SHARED static struct { 71 72 cvmx_spinlock_t lock; /**< mutex spinlock */ 73 74 struct { 75 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 */ 79 80 } s[CVMX_COREMASK_MAX_SYNCS]; 81 82} state = { 83 84 { CVMX_SPINLOCK_UNLOCKED_VAL }, 85 86 { { 0, 0, 0 } }, 87}; 88 89 90/** 91 * Wait (stall) until all cores in the given coremask has reached this point 92 * in the program execution before proceeding. 93 * 94 * @param coremask the group of cores performing the barrier sync 95 * 96 */ 97void cvmx_coremask_barrier_sync(unsigned int coremask) 98{ 99 int i; 100 unsigned int target; 101 102 assert(coremask != 0); 103 104 cvmx_spinlock_lock(&state.lock); 105 106 for (i = 0; i < CVMX_COREMASK_MAX_SYNCS; i++) { 107 108 if (state.s[i].coremask == 0) { 109 /* end of existing coremask list, create new entry, fall-thru */ 110 state.s[i].coremask = coremask; 111 } 112 113 if (state.s[i].coremask == coremask) { 114 115 target = state.s[i].exit + 1; /* wrap-around at 32b */ 116 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 */ 121 } 122 cvmx_spinlock_unlock(&state.lock); 123 124 while (state.s[i].exit != target) 125 ; 126 127 return; 128 } 129 } 130 131 /* error condition - coremask array overflowed */ 132 cvmx_spinlock_unlock(&state.lock); 133 assert(0); 134} 135