Home | History | Annotate | Download | only in machine
      1 /*	$NetBSD: acpi_func.h,v 1.2 2006/05/14 21:55:38 elad 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.2 $
     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 #define ACPI_FLUSH_CPU_CACHE()	/* XXX ia64_fc()? */
     52 
     53 
     54 /* Section 5.2.9.1:  global lock acquire/release functions */
     55 extern int	acpi_acquire_global_lock(uint32_t *lock);
     56 extern int	acpi_release_global_lock(uint32_t *lock);
     57 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
     58 		((Acq) = acpi_acquire_global_lock(GLptr))
     59 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
     60 		((Acq) = acpi_release_global_lock(GLptr))
     61 
     62 
     63 /* Section 5.2.9.1:  global lock acquire/release functions */
     64 #define GL_ACQUIRED	(-1)
     65 #define GL_BUSY		0
     66 #define GL_BIT_PENDING	0x1
     67 #define GL_BIT_OWNED	0x2
     68 #define GL_BIT_MASK	(GL_BIT_PENDING | GL_BIT_OWNED)
     69 
     70 /*
     71  * Acquire the global lock.  If busy, set the pending bit.  The caller
     72  * will wait for notification from the BIOS that the lock is available
     73  * and then attempt to acquire it again.
     74  */
     75 int
     76 acpi_acquire_global_lock(uint32_t *lock)
     77 {
     78 	uint32_t new, old;
     79 
     80 	do {
     81 		old = *lock;
     82 		new = ((old & ~GL_BIT_MASK) | GL_BIT_OWNED) |
     83 			((old >> 1) & GL_BIT_PENDING);
     84 	} while (atomic_cmpset_acq_int(lock, old, new) == 0);
     85 
     86 	return ((new < GL_BIT_MASK) ? GL_ACQUIRED : GL_BUSY);
     87 }
     88 
     89 /*
     90  * Release the global lock, returning whether there is a waiter pending.
     91  * If the BIOS set the pending bit, OSPM must notify the BIOS when it
     92  * releases the lock.
     93  */
     94 int
     95 acpi_release_global_lock(uint32_t *lock)
     96 {
     97 	uint32_t new, old;
     98 
     99 	do {
    100 		old = *lock;
    101 		new = old & ~GL_BIT_MASK;
    102 	} while (atomic_cmpset_rel_int(lock, old, new) == 0);
    103 
    104 	return (old & GL_BIT_PENDING);
    105 }
    106 
    107 #endif /* _IA64_ACPI_FUNC_H_ */
    108