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