1 /* $NetBSD: acpi_func.h,v 1.10 2008/05/24 22:02:31 jmcneill Exp $ */
3 #include <machine/cpufunc.h>
5 #include <sys/atomic.h>
7 #define GL_ACQUIRED (-1)
9 #define GL_BIT_PENDING 1
10 #define GL_BIT_OWNED 2
11 #define GL_BIT_MASK (GL_BIT_PENDING | GL_BIT_OWNED)
13 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
15 (Acq) = acpi_acquire_global_lock(&((GLptr)->GlobalLock)); \
18 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
20 (Acq) = acpi_release_global_lock(&((GLptr)->GlobalLock)); \
24 acpi_acquire_global_lock(uint32_t *lock
)
26 uint32_t new, old
, val
;
30 new = ((old
& ~GL_BIT_MASK
) | GL_BIT_OWNED
) |
31 ((old
>> 1) & GL_BIT_PENDING
);
32 val
= atomic_cas_32(lock
, old
, new);
33 } while (__predict_false(val
!= old
));
35 return ((new < GL_BIT_MASK
) ? GL_ACQUIRED
: GL_BUSY
);
39 acpi_release_global_lock(uint32_t *lock
)
41 uint32_t new, old
, val
;
45 new = old
& ~GL_BIT_MASK
;
46 val
= atomic_cas_32(lock
, old
, new);
47 } while (__predict_false(val
!= old
));
49 return old
& GL_BIT_PENDING
;
52 #define ACPI_FLUSH_CPU_CACHE() wbinvd()