aclinuxex.h 3.3 KB

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