Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux |
| 5 | * |
Bob Moore | da6f832 | 2018-01-04 10:06:38 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2018, Intel Corp. |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 9 | |
| 10 | #ifndef __ACLINUXEX_H__ |
| 11 | #define __ACLINUXEX_H__ |
| 12 | |
| 13 | #ifdef __KERNEL__ |
| 14 | |
Lv Zheng | daba25d | 2014-07-16 16:58:00 +0800 | [diff] [blame] | 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 | |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 37 | /* |
| 38 | * Overrides for in-kernel ACPICA |
| 39 | */ |
Lv Zheng | 2368b1a | 2016-08-04 16:43:19 +0800 | [diff] [blame] | 40 | acpi_status ACPI_INIT_FUNCTION acpi_os_initialize(void); |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 41 | |
| 42 | acpi_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 | */ |
| 50 | static inline void *acpi_os_allocate(acpi_size size) |
| 51 | { |
| 52 | return kmalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL); |
| 53 | } |
| 54 | |
| 55 | static inline void *acpi_os_allocate_zeroed(acpi_size size) |
| 56 | { |
| 57 | return kzalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL); |
| 58 | } |
| 59 | |
| 60 | static inline void acpi_os_free(void *memory) |
| 61 | { |
| 62 | kfree(memory); |
| 63 | } |
| 64 | |
| 65 | static inline void *acpi_os_acquire_object(acpi_cache_t * cache) |
| 66 | { |
| 67 | return kmem_cache_zalloc(cache, |
| 68 | irqs_disabled()? GFP_ATOMIC : GFP_KERNEL); |
| 69 | } |
| 70 | |
| 71 | static inline acpi_thread_id acpi_os_get_thread_id(void) |
| 72 | { |
| 73 | return (acpi_thread_id) (unsigned long)current; |
| 74 | } |
| 75 | |
| 76 | /* |
| 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. |
| 82 | */ |
| 83 | #define acpi_os_create_lock(__handle) \ |
| 84 | ({ \ |
| 85 | spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \ |
| 86 | if (lock) { \ |
| 87 | *(__handle) = lock; \ |
| 88 | spin_lock_init(*(__handle)); \ |
| 89 | } \ |
| 90 | lock ? AE_OK : AE_NO_MEMORY; \ |
| 91 | }) |
| 92 | |
Lv Zheng | 4d946f7 | 2015-10-19 10:25:56 +0800 | [diff] [blame] | 93 | static inline u8 acpi_os_readable(void *pointer, acpi_size length) |
| 94 | { |
| 95 | return TRUE; |
| 96 | } |
| 97 | |
Lv Zheng | 703ecd2 | 2016-12-28 15:28:07 +0800 | [diff] [blame] | 98 | static inline acpi_status acpi_os_initialize_debugger(void) |
Lv Zheng | f8d3148 | 2015-12-03 10:42:46 +0800 | [diff] [blame] | 99 | { |
| 100 | return AE_OK; |
| 101 | } |
| 102 | |
Lv Zheng | 703ecd2 | 2016-12-28 15:28:07 +0800 | [diff] [blame] | 103 | static inline void acpi_os_terminate_debugger(void) |
Lv Zheng | f8d3148 | 2015-12-03 10:42:46 +0800 | [diff] [blame] | 104 | { |
Lv Zheng | 5431b65 | 2015-12-29 13:52:32 +0800 | [diff] [blame] | 105 | return; |
Lv Zheng | f8d3148 | 2015-12-03 10:42:46 +0800 | [diff] [blame] | 106 | } |
| 107 | |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 108 | /* |
| 109 | * OSL interfaces added by Linux |
| 110 | */ |
Lv Zheng | d13bd5a | 2014-05-12 15:46:32 +0800 | [diff] [blame] | 111 | |
| 112 | #endif /* __KERNEL__ */ |
| 113 | |
| 114 | #endif /* __ACLINUXEX_H__ */ |