xref: /netbsd-src/sys/external/bsd/acpica/dist/include/platform/aclinuxex.h (revision 046a29855e04359424fd074e8313af6b6be8cfb6)
1460301d4Schristos /******************************************************************************
2460301d4Schristos  *
3460301d4Schristos  * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
4460301d4Schristos  *
5460301d4Schristos  *****************************************************************************/
6460301d4Schristos 
7460301d4Schristos /*
8*046a2985Schristos  * Copyright (C) 2000 - 2023, Intel Corp.
9460301d4Schristos  * All rights reserved.
10460301d4Schristos  *
11460301d4Schristos  * Redistribution and use in source and binary forms, with or without
12460301d4Schristos  * modification, are permitted provided that the following conditions
13460301d4Schristos  * are met:
14460301d4Schristos  * 1. Redistributions of source code must retain the above copyright
15460301d4Schristos  *    notice, this list of conditions, and the following disclaimer,
16460301d4Schristos  *    without modification.
17460301d4Schristos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18460301d4Schristos  *    substantially similar to the "NO WARRANTY" disclaimer below
19460301d4Schristos  *    ("Disclaimer") and any redistribution must be conditioned upon
20460301d4Schristos  *    including a substantially similar Disclaimer requirement for further
21460301d4Schristos  *    binary redistribution.
22460301d4Schristos  * 3. Neither the names of the above-listed copyright holders nor the names
23460301d4Schristos  *    of any contributors may be used to endorse or promote products derived
24460301d4Schristos  *    from this software without specific prior written permission.
25460301d4Schristos  *
26460301d4Schristos  * Alternatively, this software may be distributed under the terms of the
27460301d4Schristos  * GNU General Public License ("GPL") version 2 as published by the Free
28460301d4Schristos  * Software Foundation.
29460301d4Schristos  *
30460301d4Schristos  * NO WARRANTY
31460301d4Schristos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32460301d4Schristos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3346a330b4Schristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34460301d4Schristos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35460301d4Schristos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36460301d4Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37460301d4Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38460301d4Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39460301d4Schristos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40460301d4Schristos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41460301d4Schristos  * POSSIBILITY OF SUCH DAMAGES.
42460301d4Schristos  */
43460301d4Schristos 
44460301d4Schristos #ifndef __ACLINUXEX_H__
45460301d4Schristos #define __ACLINUXEX_H__
46460301d4Schristos 
47460301d4Schristos #ifdef __KERNEL__
48460301d4Schristos 
49460301d4Schristos #ifndef ACPI_USE_NATIVE_DIVIDE
50460301d4Schristos 
51460301d4Schristos #ifndef ACPI_DIV_64_BY_32
52460301d4Schristos #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
53460301d4Schristos     do { \
54460301d4Schristos         UINT64 (__n) = ((UINT64) n_hi) << 32 | (n_lo); \
55460301d4Schristos         (r32) = do_div ((__n), (d32)); \
56460301d4Schristos         (q32) = (UINT32) (__n); \
57460301d4Schristos     } while (0)
58460301d4Schristos #endif
59460301d4Schristos 
60460301d4Schristos #ifndef ACPI_SHIFT_RIGHT_64
61460301d4Schristos #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
62460301d4Schristos     do { \
63460301d4Schristos         (n_lo) >>= 1; \
64460301d4Schristos         (n_lo) |= (((n_hi) & 1) << 31); \
65460301d4Schristos         (n_hi) >>= 1; \
66460301d4Schristos     } while (0)
67460301d4Schristos #endif
68460301d4Schristos 
69460301d4Schristos #endif
70460301d4Schristos 
71460301d4Schristos /*
72460301d4Schristos  * Overrides for in-kernel ACPICA
73460301d4Schristos  */
74d0e1da26Schristos ACPI_STATUS ACPI_INIT_FUNCTION AcpiOsInitialize (
75460301d4Schristos     void);
76460301d4Schristos 
77460301d4Schristos ACPI_STATUS AcpiOsTerminate (
78460301d4Schristos     void);
79460301d4Schristos 
80460301d4Schristos /*
81460301d4Schristos  * The irqs_disabled() check is for resume from RAM.
82460301d4Schristos  * Interrupts are off during resume, just like they are for boot.
83460301d4Schristos  * However, boot has  (system_state != SYSTEM_RUNNING)
84460301d4Schristos  * to quiet __might_sleep() in kmalloc() and resume does not.
85460301d4Schristos  */
86460301d4Schristos static inline void *
AcpiOsAllocate(ACPI_SIZE Size)87460301d4Schristos AcpiOsAllocate (
88460301d4Schristos     ACPI_SIZE               Size)
89460301d4Schristos {
90460301d4Schristos     return kmalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
91460301d4Schristos }
92460301d4Schristos 
93460301d4Schristos static inline void *
AcpiOsAllocateZeroed(ACPI_SIZE Size)94460301d4Schristos AcpiOsAllocateZeroed (
95460301d4Schristos     ACPI_SIZE               Size)
96460301d4Schristos {
97460301d4Schristos     return kzalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
98460301d4Schristos }
99460301d4Schristos 
100460301d4Schristos static inline void
AcpiOsFree(void * Memory)101460301d4Schristos AcpiOsFree (
102460301d4Schristos     void                   *Memory)
103460301d4Schristos {
104460301d4Schristos     kfree (Memory);
105460301d4Schristos }
106460301d4Schristos 
107460301d4Schristos static inline void *
AcpiOsAcquireObject(ACPI_CACHE_T * Cache)108460301d4Schristos AcpiOsAcquireObject (
109460301d4Schristos     ACPI_CACHE_T           *Cache)
110460301d4Schristos {
111460301d4Schristos     return kmem_cache_zalloc (Cache,
112460301d4Schristos         irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
113460301d4Schristos }
114460301d4Schristos 
115460301d4Schristos static inline ACPI_THREAD_ID
AcpiOsGetThreadId(void)116460301d4Schristos AcpiOsGetThreadId (
117460301d4Schristos     void)
118460301d4Schristos {
119460301d4Schristos     return (ACPI_THREAD_ID) (unsigned long) current;
120460301d4Schristos }
121460301d4Schristos 
122460301d4Schristos /*
123460301d4Schristos  * When lockdep is enabled, the spin_lock_init() macro stringifies it's
124460301d4Schristos  * argument and uses that as a name for the lock in debugging.
125460301d4Schristos  * By executing spin_lock_init() in a macro the key changes from "lock" for
126460301d4Schristos  * all locks to the name of the argument of acpi_os_create_lock(), which
127460301d4Schristos  * prevents lockdep from reporting false positives for ACPICA locks.
128460301d4Schristos  */
129460301d4Schristos #define AcpiOsCreateLock(__Handle) \
130460301d4Schristos     ({ \
131460301d4Schristos         spinlock_t *Lock = ACPI_ALLOCATE(sizeof(*Lock)); \
132460301d4Schristos         if (Lock) { \
133460301d4Schristos             *(__Handle) = Lock; \
134460301d4Schristos             spin_lock_init(*(__Handle)); \
135460301d4Schristos         } \
136460301d4Schristos         Lock ? AE_OK : AE_NO_MEMORY; \
137460301d4Schristos     })
138460301d4Schristos 
13971e38f1dSchristos static inline BOOLEAN
AcpiOsReadable(void * Pointer,ACPI_SIZE Length)14071e38f1dSchristos AcpiOsReadable (
14171e38f1dSchristos     void                    *Pointer,
14271e38f1dSchristos     ACPI_SIZE               Length)
14371e38f1dSchristos {
14471e38f1dSchristos     return TRUE;
14571e38f1dSchristos }
14671e38f1dSchristos 
1470b89cdedSchristos static inline ACPI_STATUS
AcpiOsInitializeDebugger(void)1480b89cdedSchristos AcpiOsInitializeDebugger (
1490b89cdedSchristos     void)
1500b89cdedSchristos {
1510b89cdedSchristos     return AE_OK;
1520b89cdedSchristos }
1530b89cdedSchristos 
1540b89cdedSchristos static inline void
AcpiOsTerminateDebugger(void)1550b89cdedSchristos AcpiOsTerminateDebugger (
1560b89cdedSchristos     void)
1570b89cdedSchristos {
1580b89cdedSchristos     return;
1590b89cdedSchristos }
1600b89cdedSchristos 
16171e38f1dSchristos 
162460301d4Schristos /*
163460301d4Schristos  * OSL interfaces added by Linux
164460301d4Schristos  */
165460301d4Schristos 
166460301d4Schristos #endif /* __KERNEL__ */
167460301d4Schristos 
168460301d4Schristos #endif /* __ACLINUXEX_H__ */
169