mm: change inlined allocation helpers to account at the call site
[linux-2.6-block.git] / include / acpi / platform / aclinuxex.h
CommitLineData
95857638 1/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
d13bd5a6
LZ
2/******************************************************************************
3 *
4 * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
5 *
612c2932 6 * Copyright (C) 2000 - 2023, Intel Corp.
d13bd5a6 7 *
95857638 8 *****************************************************************************/
d13bd5a6
LZ
9
10#ifndef __ACLINUXEX_H__
11#define __ACLINUXEX_H__
12
13#ifdef __KERNEL__
14
daba25d6
LZ
15#ifndef ACPI_USE_NATIVE_DIVIDE
16
17#ifndef ACPI_DIV_64_BY_32
18#define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
19 do { \
20 u64 (__n) = ((u64) n_hi) << 32 | (n_lo); \
21 (r32) = do_div ((__n), (d32)); \
22 (q32) = (u32) (__n); \
23 } while (0)
24#endif
25
26#ifndef ACPI_SHIFT_RIGHT_64
27#define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
28 do { \
29 (n_lo) >>= 1; \
30 (n_lo) |= (((n_hi) & 1) << 31); \
31 (n_hi) >>= 1; \
32 } while (0)
33#endif
34
35#endif
36
d13bd5a6
LZ
37/*
38 * Overrides for in-kernel ACPICA
39 */
2368b1a1 40acpi_status ACPI_INIT_FUNCTION acpi_os_initialize(void);
d13bd5a6
LZ
41
42acpi_status acpi_os_terminate(void);
43
44/*
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.
49 */
2c321f3f
SB
50#define acpi_os_allocate(_size) \
51 kmalloc(_size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
d13bd5a6 52
2c321f3f
SB
53#define acpi_os_allocate_zeroed(_size) \
54 kzalloc(_size, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
d13bd5a6
LZ
55
56static inline void acpi_os_free(void *memory)
57{
58 kfree(memory);
59}
60
2c321f3f
SB
61#define acpi_os_acquire_object(_cache) \
62 kmem_cache_zalloc(_cache, irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL)
d13bd5a6
LZ
63
64static inline acpi_thread_id acpi_os_get_thread_id(void)
65{
66 return (acpi_thread_id) (unsigned long)current;
67}
68
69/*
70 * When lockdep is enabled, the spin_lock_init() macro stringifies it's
71 * argument and uses that as a name for the lock in debugging.
72 * By executing spin_lock_init() in a macro the key changes from "lock" for
73 * all locks to the name of the argument of acpi_os_create_lock(), which
74 * prevents lockdep from reporting false positives for ACPICA locks.
75 */
76#define acpi_os_create_lock(__handle) \
77 ({ \
78 spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
79 if (lock) { \
80 *(__handle) = lock; \
81 spin_lock_init(*(__handle)); \
82 } \
83 lock ? AE_OK : AE_NO_MEMORY; \
84 })
85
c3052594
SAS
86
87#define acpi_os_create_raw_lock(__handle) \
88 ({ \
89 raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
90 if (lock) { \
91 *(__handle) = lock; \
92 raw_spin_lock_init(*(__handle)); \
93 } \
94 lock ? AE_OK : AE_NO_MEMORY; \
95 })
96
97static inline acpi_cpu_flags acpi_os_acquire_raw_lock(acpi_raw_spinlock lockp)
98{
99 acpi_cpu_flags flags;
100
101 raw_spin_lock_irqsave(lockp, flags);
102 return flags;
103}
104
105static inline void acpi_os_release_raw_lock(acpi_raw_spinlock lockp,
106 acpi_cpu_flags flags)
107{
108 raw_spin_unlock_irqrestore(lockp, flags);
109}
110
111static inline void acpi_os_delete_raw_lock(acpi_raw_spinlock handle)
112{
113 ACPI_FREE(handle);
114}
115
4d946f79
LZ
116static inline u8 acpi_os_readable(void *pointer, acpi_size length)
117{
118 return TRUE;
119}
120
703ecd22 121static inline acpi_status acpi_os_initialize_debugger(void)
f8d31489
LZ
122{
123 return AE_OK;
124}
125
703ecd22 126static inline void acpi_os_terminate_debugger(void)
f8d31489 127{
5431b654 128 return;
f8d31489
LZ
129}
130
d13bd5a6
LZ
131/*
132 * OSL interfaces added by Linux
133 */
d13bd5a6
LZ
134
135#endif /* __KERNEL__ */
136
137#endif /* __ACLINUXEX_H__ */