^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __ACLINUXEX_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define __ACLINUXEX_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef ACPI_USE_NATIVE_DIVIDE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #ifndef ACPI_DIV_64_BY_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u64 (__n) = ((u64) n_hi) << 32 | (n_lo); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) (r32) = do_div ((__n), (d32)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) (q32) = (u32) (__n); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #ifndef ACPI_SHIFT_RIGHT_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) (n_lo) >>= 1; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) (n_lo) |= (((n_hi) & 1) << 31); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) (n_hi) >>= 1; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Overrides for in-kernel ACPICA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) acpi_status ACPI_INIT_FUNCTION acpi_os_initialize(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) acpi_status acpi_os_terminate(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * The irqs_disabled() check is for resume from RAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Interrupts are off during resume, just like they are for boot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * However, boot has (system_state != SYSTEM_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * to quiet __might_sleep() in kmalloc() and resume does not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static inline void *acpi_os_allocate(acpi_size size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return kmalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static inline void *acpi_os_allocate_zeroed(acpi_size size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return kzalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline void acpi_os_free(void *memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) kfree(memory);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static inline void *acpi_os_acquire_object(acpi_cache_t * cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return kmem_cache_zalloc(cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static inline acpi_thread_id acpi_os_get_thread_id(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return (acpi_thread_id) (unsigned long)current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * When lockdep is enabled, the spin_lock_init() macro stringifies it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * argument and uses that as a name for the lock in debugging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * By executing spin_lock_init() in a macro the key changes from "lock" for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * all locks to the name of the argument of acpi_os_create_lock(), which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * prevents lockdep from reporting false positives for ACPICA locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define acpi_os_create_lock(__handle) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (lock) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *(__handle) = lock; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) spin_lock_init(*(__handle)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) lock ? AE_OK : AE_NO_MEMORY; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define acpi_os_create_raw_lock(__handle) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (lock) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *(__handle) = lock; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) raw_spin_lock_init(*(__handle)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) lock ? AE_OK : AE_NO_MEMORY; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static inline acpi_cpu_flags acpi_os_acquire_raw_lock(acpi_raw_spinlock lockp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) acpi_cpu_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) raw_spin_lock_irqsave(lockp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static inline void acpi_os_release_raw_lock(acpi_raw_spinlock lockp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) acpi_cpu_flags flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) raw_spin_unlock_irqrestore(lockp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static inline void acpi_os_delete_raw_lock(acpi_raw_spinlock handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ACPI_FREE(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline u8 acpi_os_readable(void *pointer, acpi_size length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static inline acpi_status acpi_os_initialize_debugger(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline void acpi_os_terminate_debugger(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * OSL interfaces added by Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #endif /* __KERNEL__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif /* __ACLINUXEX_H__ */