1/* $NetBSD: acpi_func.h,v 1.3 2010/07/24 09:35:36 jruoho Exp $ */ 2 3/*- 4 * Copyright (c) 2002 Mitsuru IWASAKI 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD: src/sys/ia64/include/acpica_machdep.h,v 1.4 2004/10/11 05:39:15 njl Exp $ 29 */ 30 31/****************************************************************************** 32 * 33 * Name: acpica_machdep.h - arch-specific defines, etc. 34 * $Revision: 1.4 $ 35 * 36 *****************************************************************************/ 37 38#ifndef _IA64_ACPI_FUNC_H_ 39#define _IA64_ACPI_FUNC_H_ 40 41#include <machine/cpufunc.h> 42#include <machine/atomic.h> 43 44/* Asm macros */ 45 46#define ACPI_ASM_MACROS 47#define BREAKPOINT3 48#define ACPI_DISABLE_IRQS() disable_intr() 49#define ACPI_ENABLE_IRQS() enable_intr() 50 51/* Section 5.2.9.1: global lock acquire/release functions */ 52extern int acpi_acquire_global_lock(uint32_t *lock); 53extern int acpi_release_global_lock(uint32_t *lock); 54#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \ 55 ((Acq) = acpi_acquire_global_lock(GLptr)) 56#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \ 57 ((Acq) = acpi_release_global_lock(GLptr)) 58 59 60/* Section 5.2.9.1: global lock acquire/release functions */ 61#define GL_ACQUIRED (-1) 62#define GL_BUSY 0 63#define GL_BIT_PENDING 0x1 64#define GL_BIT_OWNED 0x2 65#define GL_BIT_MASK (GL_BIT_PENDING | GL_BIT_OWNED) 66 67/* 68 * Acquire the global lock. If busy, set the pending bit. The caller 69 * will wait for notification from the BIOS that the lock is available 70 * and then attempt to acquire it again. 71 */ 72int 73acpi_acquire_global_lock(uint32_t *lock) 74{ 75 uint32_t new, old; 76 77 do { 78 old = *lock; 79 new = ((old & ~GL_BIT_MASK) | GL_BIT_OWNED) | 80 ((old >> 1) & GL_BIT_PENDING); 81 } while (atomic_cmpset_acq_int(lock, old, new) == 0); 82 83 return ((new < GL_BIT_MASK) ? GL_ACQUIRED : GL_BUSY); 84} 85 86/* 87 * Release the global lock, returning whether there is a waiter pending. 88 * If the BIOS set the pending bit, OSPM must notify the BIOS when it 89 * releases the lock. 90 */ 91int 92acpi_release_global_lock(uint32_t *lock) 93{ 94 uint32_t new, old; 95 96 do { 97 old = *lock; 98 new = old & ~GL_BIT_MASK; 99 } while (atomic_cmpset_rel_int(lock, old, new) == 0); 100 101 return (old & GL_BIT_PENDING); 102} 103 104#endif /* _IA64_ACPI_FUNC_H_ */ 105