fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_init_rmlock (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise global locks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called at driver initialisation time to allocate necessary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data structures.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_nsc_rmspin_slp, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_lock_top.next = _nsc_lock_top.prev = &_nsc_lock_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&_nsc_global_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_deinit_rmlock (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * De-initialise global locks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called at driver unload time to de-allocate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * resources.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_lock_all_rm (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Take all global locks in address order.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 if _nsc_unlock_all_rm() should be called, or -1.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lp = _nsc_lock_top.next; lp != &_nsc_lock_top; lp = lp->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_unlock_all_rm (void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Release all global locks in reverse address order.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lp = _nsc_lock_top.prev; lp != &_nsc_lock_top; lp = lp->prev) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rmlock_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_lock_alloc(char *name, int flag, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate and initialise a global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The 'flag' parameter should be either KM_SLEEP or KM_NOSLEEP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * depending on whether the caller is willing to sleep while memory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is allocated or not.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The 'arg' parameter is passed directly to the underlying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mutex_init(9f) function call.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns NULL if lock cannot be allocated.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_rm_lock_alloc(char *name, int flag, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((lk = (nsc_rmlock_t *)nsc_kmem_zalloc(sizeof (*lk),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (lp = _nsc_lock_top.next; lp != &_nsc_lock_top; lp = lp->next)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: rmlock double allocation (%s)", name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_lock_destroy(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Release the global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The specified global lock is released and made
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * available for reallocation.
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!nsctl: rmlock destroyed when locked (%s)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_lock(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Acquire a global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rmlockp is the lock to be acquired.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 (success) or errno. Lock is not acquired if rc != 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* always use a write-lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * static void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_rm_unlock(nsc_rmlock_t *rmlockp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Unlock a global lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rmlockp is the lock to be released.