aclinuxex.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /******************************************************************************
  2. *
  3. * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2017, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #ifndef __ACLINUXEX_H__
  43. #define __ACLINUXEX_H__
  44. #ifdef __KERNEL__
  45. #ifndef ACPI_USE_NATIVE_DIVIDE
  46. #ifndef ACPI_DIV_64_BY_32
  47. #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
  48. do { \
  49. u64 (__n) = ((u64) n_hi) << 32 | (n_lo); \
  50. (r32) = do_div ((__n), (d32)); \
  51. (q32) = (u32) (__n); \
  52. } while (0)
  53. #endif
  54. #ifndef ACPI_SHIFT_RIGHT_64
  55. #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
  56. do { \
  57. (n_lo) >>= 1; \
  58. (n_lo) |= (((n_hi) & 1) << 31); \
  59. (n_hi) >>= 1; \
  60. } while (0)
  61. #endif
  62. #endif
  63. /*
  64. * Overrides for in-kernel ACPICA
  65. */
  66. acpi_status ACPI_INIT_FUNCTION acpi_os_initialize(void);
  67. acpi_status acpi_os_terminate(void);
  68. /*
  69. * The irqs_disabled() check is for resume from RAM.
  70. * Interrupts are off during resume, just like they are for boot.
  71. * However, boot has (system_state != SYSTEM_RUNNING)
  72. * to quiet __might_sleep() in kmalloc() and resume does not.
  73. */
  74. static inline void *acpi_os_allocate(acpi_size size)
  75. {
  76. return kmalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
  77. }
  78. static inline void *acpi_os_allocate_zeroed(acpi_size size)
  79. {
  80. return kzalloc(size, irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
  81. }
  82. static inline void acpi_os_free(void *memory)
  83. {
  84. kfree(memory);
  85. }
  86. static inline void *acpi_os_acquire_object(acpi_cache_t * cache)
  87. {
  88. return kmem_cache_zalloc(cache,
  89. irqs_disabled()? GFP_ATOMIC : GFP_KERNEL);
  90. }
  91. static inline acpi_thread_id acpi_os_get_thread_id(void)
  92. {
  93. return (acpi_thread_id) (unsigned long)current;
  94. }
  95. /*
  96. * When lockdep is enabled, the spin_lock_init() macro stringifies it's
  97. * argument and uses that as a name for the lock in debugging.
  98. * By executing spin_lock_init() in a macro the key changes from "lock" for
  99. * all locks to the name of the argument of acpi_os_create_lock(), which
  100. * prevents lockdep from reporting false positives for ACPICA locks.
  101. */
  102. #define acpi_os_create_lock(__handle) \
  103. ({ \
  104. spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
  105. if (lock) { \
  106. *(__handle) = lock; \
  107. spin_lock_init(*(__handle)); \
  108. } \
  109. lock ? AE_OK : AE_NO_MEMORY; \
  110. })
  111. static inline u8 acpi_os_readable(void *pointer, acpi_size length)
  112. {
  113. return TRUE;
  114. }
  115. static inline acpi_status acpi_os_initialize_debugger(void)
  116. {
  117. return AE_OK;
  118. }
  119. static inline void acpi_os_terminate_debugger(void)
  120. {
  121. return;
  122. }
  123. /*
  124. * OSL interfaces added by Linux
  125. */
  126. #endif /* __KERNEL__ */
  127. #endif /* __ACLINUXEX_H__ */