17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*b5b48cc1Ssudheer * Common Development and Distribution License (the "License"). 6*b5b48cc1Ssudheer * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*b5b48cc1Ssudheer * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_MACHLOCK_H 277c478bd9Sstevel@tonic-gate #define _SYS_MACHLOCK_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifdef __cplusplus 327c478bd9Sstevel@tonic-gate extern "C" { 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifndef _ASM 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include <sys/types.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef _KERNEL 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate extern void lock_set(lock_t *lp); 427c478bd9Sstevel@tonic-gate extern int lock_try(lock_t *lp); 437c478bd9Sstevel@tonic-gate extern int lock_spin_try(lock_t *lp); 447c478bd9Sstevel@tonic-gate extern int ulock_try(lock_t *lp); 457c478bd9Sstevel@tonic-gate extern void ulock_clear(lock_t *lp); 467c478bd9Sstevel@tonic-gate extern void lock_clear(lock_t *lp); 477c478bd9Sstevel@tonic-gate extern void lock_set_spl(lock_t *lp, int new_pil, ushort_t *old_pil); 487c478bd9Sstevel@tonic-gate extern void lock_clear_splx(lock_t *lp, int s); 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define LOCK_HELD_VALUE 0xff 537c478bd9Sstevel@tonic-gate #define LOCK_INIT_CLEAR(lp) (*(lp) = 0) 547c478bd9Sstevel@tonic-gate #define LOCK_INIT_HELD(lp) (*(lp) = LOCK_HELD_VALUE) 557c478bd9Sstevel@tonic-gate #define LOCK_HELD(lp) (*(volatile lock_t *)(lp) != 0) 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate typedef lock_t disp_lock_t; /* dispatcher lock type */ 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* 607c478bd9Sstevel@tonic-gate * SPIN_LOCK() macro indicates whether lock is implemented as a spin lock or 617c478bd9Sstevel@tonic-gate * an adaptive mutex, depending on what interrupt levels use it. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define SPIN_LOCK(pl) ((pl) > ipltospl(LOCK_LEVEL)) 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * Macro to control loops which spin on a lock and then check state 677c478bd9Sstevel@tonic-gate * periodically. Its passed an integer, and returns a boolean value 687c478bd9Sstevel@tonic-gate * that if true indicates its a good time to get the scheduler lock and 697c478bd9Sstevel@tonic-gate * check the state of the current owner of the lock. 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate #define LOCK_SAMPLE_INTERVAL(i) (((i) & 0xff) == 0) 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * Extern for CLOCK_LOCK. 757c478bd9Sstevel@tonic-gate */ 76*b5b48cc1Ssudheer extern volatile int hres_lock; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #endif /* _ASM */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * The definitions of the symbolic interrupt levels: 827c478bd9Sstevel@tonic-gate * 837c478bd9Sstevel@tonic-gate * CLOCK_LEVEL => The level at which one must be to block the clock. 847c478bd9Sstevel@tonic-gate * 857c478bd9Sstevel@tonic-gate * LOCK_LEVEL => The highest level at which one may block (and thus the 867c478bd9Sstevel@tonic-gate * highest level at which one may acquire adaptive locks) 877c478bd9Sstevel@tonic-gate * Also the highest level at which one may be preempted. 887c478bd9Sstevel@tonic-gate * 897c478bd9Sstevel@tonic-gate * DISP_LEVEL => The level at which one must be to perform dispatcher 907c478bd9Sstevel@tonic-gate * operations. 917c478bd9Sstevel@tonic-gate * 927c478bd9Sstevel@tonic-gate * The constraints on the platform: 937c478bd9Sstevel@tonic-gate * 947c478bd9Sstevel@tonic-gate * - CLOCK_LEVEL must be less than or equal to LOCK_LEVEL 957c478bd9Sstevel@tonic-gate * - LOCK_LEVEL must be less than DISP_LEVEL 967c478bd9Sstevel@tonic-gate * - DISP_LEVEL should be as close to LOCK_LEVEL as possible 977c478bd9Sstevel@tonic-gate * 987c478bd9Sstevel@tonic-gate * Note that LOCK_LEVEL and CLOCK_LEVEL have historically always been equal; 997c478bd9Sstevel@tonic-gate * changing this relationship is probably possible but not advised. 1007c478bd9Sstevel@tonic-gate * 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate #define CLOCK_LEVEL 10 1037c478bd9Sstevel@tonic-gate #define LOCK_LEVEL 10 1047c478bd9Sstevel@tonic-gate #define DISP_LEVEL (LOCK_LEVEL + 1) 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define HIGH_LEVELS (PIL_MAX - LOCK_LEVEL) 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #define PIL_MAX 15 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * The mutex and semaphore code depends on being able to represent a lock 1127c478bd9Sstevel@tonic-gate * plus owner in a single 32-bit word. Thus the owner must contain at most 1137c478bd9Sstevel@tonic-gate * 24 significant bits. At present only threads, mutexes and semaphores 1147c478bd9Sstevel@tonic-gate * must be aware of this vile constraint. Different ISAs may handle this 1157c478bd9Sstevel@tonic-gate * differently depending on their capabilities (e.g. compare-and-swap) 1167c478bd9Sstevel@tonic-gate * and limitations (e.g. constraints on alignment and/or KERNELBASE). 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate #define PTR24_LSB 5 /* lower bits all zero */ 1197c478bd9Sstevel@tonic-gate #define PTR24_MSB (PTR24_LSB + 24) /* upper bits all one */ 1207c478bd9Sstevel@tonic-gate #define PTR24_ALIGN 32 /* minimum alignment (1 << lsb) */ 1217c478bd9Sstevel@tonic-gate #define PTR24_BASE 0xe0000000 /* minimum ptr value (-1 >> (32-msb)) */ 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate #endif 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #endif /* _SYS_MACHLOCK_H */ 128