1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /******************************************************************************
4 * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #ifndef __ACLINUXEX_H__
11 #define __ACLINUXEX_H__
15 #ifndef ACPI_USE_NATIVE_DIVIDE
17 #ifndef ACPI_DIV_64_BY_32
18 #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
20 u64 (__n) = ((u64) n_hi) << 32 | (n_lo); \
21 (r32) = do_div ((__n), (d32)); \
22 (q32) = (u32) (__n); \
26 #ifndef ACPI_SHIFT_RIGHT_64
27 #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
30 (n_lo) |= (((n_hi) & 1) << 31); \
38 * Overrides for in-kernel ACPICA
40 acpi_status ACPI_INIT_FUNCTION
acpi_os_initialize(void);
42 acpi_status
acpi_os_terminate(void);
45 * The irqs_disabled() check is for resume from RAM.
46 * Interrupts are off during resume, just like they are for boot.
47 * However, boot has (system_state != SYSTEM_RUNNING)
48 * to quiet __might_sleep() in kmalloc() and resume does not.
50 static inline void *acpi_os_allocate(acpi_size size
)
52 return kmalloc(size
, irqs_disabled()? GFP_ATOMIC
: GFP_KERNEL
);
55 static inline void *acpi_os_allocate_zeroed(acpi_size size
)
57 return kzalloc(size
, irqs_disabled()? GFP_ATOMIC
: GFP_KERNEL
);
60 static inline void acpi_os_free(void *memory
)
65 static inline void *acpi_os_acquire_object(acpi_cache_t
* cache
)
67 return kmem_cache_zalloc(cache
,
68 irqs_disabled()? GFP_ATOMIC
: GFP_KERNEL
);
71 static inline acpi_thread_id
acpi_os_get_thread_id(void)
73 return (acpi_thread_id
) (unsigned long)current
;
77 * When lockdep is enabled, the spin_lock_init() macro stringifies it's
78 * argument and uses that as a name for the lock in debugging.
79 * By executing spin_lock_init() in a macro the key changes from "lock" for
80 * all locks to the name of the argument of acpi_os_create_lock(), which
81 * prevents lockdep from reporting false positives for ACPICA locks.
83 #define acpi_os_create_lock(__handle) \
85 spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
88 spin_lock_init(*(__handle)); \
90 lock ? AE_OK : AE_NO_MEMORY; \
94 #define acpi_os_create_raw_lock(__handle) \
96 raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
99 raw_spin_lock_init(*(__handle)); \
101 lock ? AE_OK : AE_NO_MEMORY; \
104 static inline acpi_cpu_flags
acpi_os_acquire_raw_lock(acpi_raw_spinlock lockp
)
106 acpi_cpu_flags flags
;
108 raw_spin_lock_irqsave(lockp
, flags
);
112 static inline void acpi_os_release_raw_lock(acpi_raw_spinlock lockp
,
113 acpi_cpu_flags flags
)
115 raw_spin_unlock_irqrestore(lockp
, flags
);
118 static inline void acpi_os_delete_raw_lock(acpi_raw_spinlock handle
)
123 static inline u8
acpi_os_readable(void *pointer
, acpi_size length
)
128 static inline acpi_status
acpi_os_initialize_debugger(void)
133 static inline void acpi_os_terminate_debugger(void)
139 * OSL interfaces added by Linux
142 #endif /* __KERNEL__ */
144 #endif /* __ACLINUXEX_H__ */