Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
0002 /******************************************************************************
0003  *
0004  * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #ifndef __ACLINUXEX_H__
0011 #define __ACLINUXEX_H__
0012 
0013 #ifdef __KERNEL__
0014 
0015 #ifndef ACPI_USE_NATIVE_DIVIDE
0016 
0017 #ifndef ACPI_DIV_64_BY_32
0018 #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
0019     do { \
0020         u64 (__n) = ((u64) n_hi) << 32 | (n_lo); \
0021         (r32) = do_div ((__n), (d32)); \
0022         (q32) = (u32) (__n); \
0023     } while (0)
0024 #endif
0025 
0026 #ifndef ACPI_SHIFT_RIGHT_64
0027 #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
0028     do { \
0029         (n_lo) >>= 1; \
0030         (n_lo) |= (((n_hi) & 1) << 31); \
0031         (n_hi) >>= 1; \
0032     } while (0)
0033 #endif
0034 
0035 #endif
0036 
0037 /*
0038  * Overrides for in-kernel ACPICA
0039  */
0040 acpi_status ACPI_INIT_FUNCTION acpi_os_initialize(void);
0041 
0042 acpi_status acpi_os_terminate(void);
0043 
0044 /*
0045  * The irqs_disabled() check is for resume from RAM.
0046  * Interrupts are off during resume, just like they are for boot.
0047  * However, boot has  (system_state != SYSTEM_RUNNING)
0048  * to quiet __might_sleep() in kmalloc() and resume does not.
0049  */
0050 static inline void *acpi_os_allocate(acpi_size size)
0051 {
0052     return kmalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
0053 }
0054 
0055 static inline void *acpi_os_allocate_zeroed(acpi_size size)
0056 {
0057     return kzalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
0058 }
0059 
0060 static inline void acpi_os_free(void *memory)
0061 {
0062     kfree(memory);
0063 }
0064 
0065 static inline void *acpi_os_acquire_object(acpi_cache_t * cache)
0066 {
0067     return kmem_cache_zalloc(cache,
0068                  irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
0069 }
0070 
0071 static inline acpi_thread_id acpi_os_get_thread_id(void)
0072 {
0073     return (acpi_thread_id) (unsigned long)current;
0074 }
0075 
0076 /*
0077  * When lockdep is enabled, the spin_lock_init() macro stringifies it's
0078  * argument and uses that as a name for the lock in debugging.
0079  * By executing spin_lock_init() in a macro the key changes from "lock" for
0080  * all locks to the name of the argument of acpi_os_create_lock(), which
0081  * prevents lockdep from reporting false positives for ACPICA locks.
0082  */
0083 #define acpi_os_create_lock(__handle) \
0084     ({ \
0085         spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
0086         if (lock) { \
0087             *(__handle) = lock; \
0088             spin_lock_init(*(__handle)); \
0089         } \
0090         lock ? AE_OK : AE_NO_MEMORY; \
0091     })
0092 
0093 
0094 #define acpi_os_create_raw_lock(__handle) \
0095     ({ \
0096         raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
0097         if (lock) { \
0098             *(__handle) = lock; \
0099             raw_spin_lock_init(*(__handle)); \
0100         } \
0101         lock ? AE_OK : AE_NO_MEMORY; \
0102     })
0103 
0104 static inline acpi_cpu_flags acpi_os_acquire_raw_lock(acpi_raw_spinlock lockp)
0105 {
0106     acpi_cpu_flags flags;
0107 
0108     raw_spin_lock_irqsave(lockp, flags);
0109     return flags;
0110 }
0111 
0112 static inline void acpi_os_release_raw_lock(acpi_raw_spinlock lockp,
0113                         acpi_cpu_flags flags)
0114 {
0115     raw_spin_unlock_irqrestore(lockp, flags);
0116 }
0117 
0118 static inline void acpi_os_delete_raw_lock(acpi_raw_spinlock handle)
0119 {
0120     ACPI_FREE(handle);
0121 }
0122 
0123 static inline u8 acpi_os_readable(void *pointer, acpi_size length)
0124 {
0125     return TRUE;
0126 }
0127 
0128 static inline acpi_status acpi_os_initialize_debugger(void)
0129 {
0130     return AE_OK;
0131 }
0132 
0133 static inline void acpi_os_terminate_debugger(void)
0134 {
0135     return;
0136 }
0137 
0138 /*
0139  * OSL interfaces added by Linux
0140  */
0141 
0142 #endif              /* __KERNEL__ */
0143 
0144 #endif              /* __ACLINUXEX_H__ */