1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
207d83914SLv Zheng /*
307d83914SLv Zheng * IA64 specific ACPICA environments and implementation
407d83914SLv Zheng *
507d83914SLv Zheng * Copyright (C) 2014, Intel Corporation
607d83914SLv Zheng * Author: Lv Zheng <lv.zheng@intel.com>
707d83914SLv Zheng */
807d83914SLv Zheng
907d83914SLv Zheng #ifndef _ASM_IA64_ACENV_H
1007d83914SLv Zheng #define _ASM_IA64_ACENV_H
1107d83914SLv Zheng
1207d83914SLv Zheng #include <asm/intrinsics.h>
1307d83914SLv Zheng
1407d83914SLv Zheng #define COMPILER_DEPENDENT_INT64 long
1507d83914SLv Zheng #define COMPILER_DEPENDENT_UINT64 unsigned long
1607d83914SLv Zheng
1707d83914SLv Zheng /* Asm macros */
1807d83914SLv Zheng
1907d83914SLv Zheng static inline int
ia64_acpi_acquire_global_lock(unsigned int * lock)2007d83914SLv Zheng ia64_acpi_acquire_global_lock(unsigned int *lock)
2107d83914SLv Zheng {
2207d83914SLv Zheng unsigned int old, new, val;
2307d83914SLv Zheng do {
2407d83914SLv Zheng old = *lock;
2507d83914SLv Zheng new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
2607d83914SLv Zheng val = ia64_cmpxchg4_acq(lock, new, old);
2707d83914SLv Zheng } while (unlikely (val != old));
2807d83914SLv Zheng return (new < 3) ? -1 : 0;
2907d83914SLv Zheng }
3007d83914SLv Zheng
3107d83914SLv Zheng static inline int
ia64_acpi_release_global_lock(unsigned int * lock)3207d83914SLv Zheng ia64_acpi_release_global_lock(unsigned int *lock)
3307d83914SLv Zheng {
3407d83914SLv Zheng unsigned int old, new, val;
3507d83914SLv Zheng do {
3607d83914SLv Zheng old = *lock;
3707d83914SLv Zheng new = old & ~0x3;
3807d83914SLv Zheng val = ia64_cmpxchg4_acq(lock, new, old);
3907d83914SLv Zheng } while (unlikely (val != old));
4007d83914SLv Zheng return old & 0x1;
4107d83914SLv Zheng }
4207d83914SLv Zheng
4307d83914SLv Zheng #define ACPI_ACQUIRE_GLOBAL_LOCK(facs, Acq) \
4407d83914SLv Zheng ((Acq) = ia64_acpi_acquire_global_lock(&facs->global_lock))
4507d83914SLv Zheng
4607d83914SLv Zheng #define ACPI_RELEASE_GLOBAL_LOCK(facs, Acq) \
4707d83914SLv Zheng ((Acq) = ia64_acpi_release_global_lock(&facs->global_lock))
4807d83914SLv Zheng
4907d83914SLv Zheng #endif /* _ASM_IA64_ACENV_H */
50