xref: /dflybsd-src/sys/contrib/dev/acpica/source/include/platform/aclinuxex.h (revision 383048aca08c2de51d27aa8638a36982a0d74550)
15f39c7e7SSascha Wildner /******************************************************************************
25f39c7e7SSascha Wildner  *
35f39c7e7SSascha Wildner  * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux
45f39c7e7SSascha Wildner  *
55f39c7e7SSascha Wildner  *****************************************************************************/
65f39c7e7SSascha Wildner 
7b4315fc7SSascha Wildner /******************************************************************************
8b4315fc7SSascha Wildner  *
9b4315fc7SSascha Wildner  * 1. Copyright Notice
10b4315fc7SSascha Wildner  *
11*383048acSSascha Wildner  * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
125f39c7e7SSascha Wildner  * All rights reserved.
135f39c7e7SSascha Wildner  *
14b4315fc7SSascha Wildner  * 2. License
15b4315fc7SSascha Wildner  *
16b4315fc7SSascha Wildner  * 2.1. This is your license from Intel Corp. under its intellectual property
17b4315fc7SSascha Wildner  * rights. You may have additional license terms from the party that provided
18b4315fc7SSascha Wildner  * you this software, covering your right to use that party's intellectual
19b4315fc7SSascha Wildner  * property rights.
20b4315fc7SSascha Wildner  *
21b4315fc7SSascha Wildner  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22b4315fc7SSascha Wildner  * copy of the source code appearing in this file ("Covered Code") an
23b4315fc7SSascha Wildner  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24b4315fc7SSascha Wildner  * base code distributed originally by Intel ("Original Intel Code") to copy,
25b4315fc7SSascha Wildner  * make derivatives, distribute, use and display any portion of the Covered
26b4315fc7SSascha Wildner  * Code in any form, with the right to sublicense such rights; and
27b4315fc7SSascha Wildner  *
28b4315fc7SSascha Wildner  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29b4315fc7SSascha Wildner  * license (with the right to sublicense), under only those claims of Intel
30b4315fc7SSascha Wildner  * patents that are infringed by the Original Intel Code, to make, use, sell,
31b4315fc7SSascha Wildner  * offer to sell, and import the Covered Code and derivative works thereof
32b4315fc7SSascha Wildner  * solely to the minimum extent necessary to exercise the above copyright
33b4315fc7SSascha Wildner  * license, and in no event shall the patent license extend to any additions
34b4315fc7SSascha Wildner  * to or modifications of the Original Intel Code. No other license or right
35b4315fc7SSascha Wildner  * is granted directly or by implication, estoppel or otherwise;
36b4315fc7SSascha Wildner  *
37b4315fc7SSascha Wildner  * The above copyright and patent license is granted only if the following
38b4315fc7SSascha Wildner  * conditions are met:
39b4315fc7SSascha Wildner  *
40b4315fc7SSascha Wildner  * 3. Conditions
41b4315fc7SSascha Wildner  *
42b4315fc7SSascha Wildner  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43b4315fc7SSascha Wildner  * Redistribution of source code of any substantial portion of the Covered
44b4315fc7SSascha Wildner  * Code or modification with rights to further distribute source must include
45b4315fc7SSascha Wildner  * the above Copyright Notice, the above License, this list of Conditions,
46b4315fc7SSascha Wildner  * and the following Disclaimer and Export Compliance provision. In addition,
47b4315fc7SSascha Wildner  * Licensee must cause all Covered Code to which Licensee contributes to
48b4315fc7SSascha Wildner  * contain a file documenting the changes Licensee made to create that Covered
49b4315fc7SSascha Wildner  * Code and the date of any change. Licensee must include in that file the
50b4315fc7SSascha Wildner  * documentation of any changes made by any predecessor Licensee. Licensee
51b4315fc7SSascha Wildner  * must include a prominent statement that the modification is derived,
52b4315fc7SSascha Wildner  * directly or indirectly, from Original Intel Code.
53b4315fc7SSascha Wildner  *
54b4315fc7SSascha Wildner  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55b4315fc7SSascha Wildner  * Redistribution of source code of any substantial portion of the Covered
56b4315fc7SSascha Wildner  * Code or modification without rights to further distribute source must
57b4315fc7SSascha Wildner  * include the following Disclaimer and Export Compliance provision in the
58b4315fc7SSascha Wildner  * documentation and/or other materials provided with distribution. In
59b4315fc7SSascha Wildner  * addition, Licensee may not authorize further sublicense of source of any
60b4315fc7SSascha Wildner  * portion of the Covered Code, and must include terms to the effect that the
61b4315fc7SSascha Wildner  * license from Licensee to its licensee is limited to the intellectual
62b4315fc7SSascha Wildner  * property embodied in the software Licensee provides to its licensee, and
63b4315fc7SSascha Wildner  * not to intellectual property embodied in modifications its licensee may
64b4315fc7SSascha Wildner  * make.
65b4315fc7SSascha Wildner  *
66b4315fc7SSascha Wildner  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67b4315fc7SSascha Wildner  * substantial portion of the Covered Code or modification must reproduce the
68b4315fc7SSascha Wildner  * above Copyright Notice, and the following Disclaimer and Export Compliance
69b4315fc7SSascha Wildner  * provision in the documentation and/or other materials provided with the
70b4315fc7SSascha Wildner  * distribution.
71b4315fc7SSascha Wildner  *
72b4315fc7SSascha Wildner  * 3.4. Intel retains all right, title, and interest in and to the Original
73b4315fc7SSascha Wildner  * Intel Code.
74b4315fc7SSascha Wildner  *
75b4315fc7SSascha Wildner  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76b4315fc7SSascha Wildner  * Intel shall be used in advertising or otherwise to promote the sale, use or
77b4315fc7SSascha Wildner  * other dealings in products derived from or relating to the Covered Code
78b4315fc7SSascha Wildner  * without prior written authorization from Intel.
79b4315fc7SSascha Wildner  *
80b4315fc7SSascha Wildner  * 4. Disclaimer and Export Compliance
81b4315fc7SSascha Wildner  *
82b4315fc7SSascha Wildner  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83b4315fc7SSascha Wildner  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84b4315fc7SSascha Wildner  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85b4315fc7SSascha Wildner  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86b4315fc7SSascha Wildner  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87b4315fc7SSascha Wildner  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88b4315fc7SSascha Wildner  * PARTICULAR PURPOSE.
89b4315fc7SSascha Wildner  *
90b4315fc7SSascha Wildner  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91b4315fc7SSascha Wildner  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92b4315fc7SSascha Wildner  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93b4315fc7SSascha Wildner  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94b4315fc7SSascha Wildner  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95b4315fc7SSascha Wildner  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96b4315fc7SSascha Wildner  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97b4315fc7SSascha Wildner  * LIMITED REMEDY.
98b4315fc7SSascha Wildner  *
99b4315fc7SSascha Wildner  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100b4315fc7SSascha Wildner  * software or system incorporating such software without first obtaining any
101b4315fc7SSascha Wildner  * required license or other approval from the U. S. Department of Commerce or
102b4315fc7SSascha Wildner  * any other agency or department of the United States Government. In the
103b4315fc7SSascha Wildner  * event Licensee exports any such software from the United States or
104b4315fc7SSascha Wildner  * re-exports any such software from a foreign destination, Licensee shall
105b4315fc7SSascha Wildner  * ensure that the distribution and export/re-export of the software is in
106b4315fc7SSascha Wildner  * compliance with all laws, regulations, orders, or other restrictions of the
107b4315fc7SSascha Wildner  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108b4315fc7SSascha Wildner  * any of its subsidiaries will export/re-export any technical data, process,
109b4315fc7SSascha Wildner  * software, or service, directly or indirectly, to any country for which the
110b4315fc7SSascha Wildner  * United States government or any agency thereof requires an export license,
111b4315fc7SSascha Wildner  * other governmental approval, or letter of assurance, without first obtaining
112b4315fc7SSascha Wildner  * such license, approval or letter.
113b4315fc7SSascha Wildner  *
114b4315fc7SSascha Wildner  *****************************************************************************
115b4315fc7SSascha Wildner  *
116b4315fc7SSascha Wildner  * Alternatively, you may choose to be licensed under the terms of the
117b4315fc7SSascha Wildner  * following license:
118b4315fc7SSascha Wildner  *
1195f39c7e7SSascha Wildner  * Redistribution and use in source and binary forms, with or without
1205f39c7e7SSascha Wildner  * modification, are permitted provided that the following conditions
1215f39c7e7SSascha Wildner  * are met:
1225f39c7e7SSascha Wildner  * 1. Redistributions of source code must retain the above copyright
1235f39c7e7SSascha Wildner  *    notice, this list of conditions, and the following disclaimer,
1245f39c7e7SSascha Wildner  *    without modification.
1255f39c7e7SSascha Wildner  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1265f39c7e7SSascha Wildner  *    substantially similar to the "NO WARRANTY" disclaimer below
1275f39c7e7SSascha Wildner  *    ("Disclaimer") and any redistribution must be conditioned upon
1285f39c7e7SSascha Wildner  *    including a substantially similar Disclaimer requirement for further
1295f39c7e7SSascha Wildner  *    binary redistribution.
1305f39c7e7SSascha Wildner  * 3. Neither the names of the above-listed copyright holders nor the names
1315f39c7e7SSascha Wildner  *    of any contributors may be used to endorse or promote products derived
1325f39c7e7SSascha Wildner  *    from this software without specific prior written permission.
1335f39c7e7SSascha Wildner  *
134b4315fc7SSascha Wildner  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135b4315fc7SSascha Wildner  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136b4315fc7SSascha Wildner  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137b4315fc7SSascha Wildner  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138b4315fc7SSascha Wildner  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139b4315fc7SSascha Wildner  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140b4315fc7SSascha Wildner  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141b4315fc7SSascha Wildner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142b4315fc7SSascha Wildner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143b4315fc7SSascha Wildner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144b4315fc7SSascha Wildner  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145b4315fc7SSascha Wildner  *
146b4315fc7SSascha Wildner  * Alternatively, you may choose to be licensed under the terms of the
1475f39c7e7SSascha Wildner  * GNU General Public License ("GPL") version 2 as published by the Free
1485f39c7e7SSascha Wildner  * Software Foundation.
1495f39c7e7SSascha Wildner  *
150b4315fc7SSascha Wildner  *****************************************************************************/
1515f39c7e7SSascha Wildner 
1525f39c7e7SSascha Wildner #ifndef __ACLINUXEX_H__
1535f39c7e7SSascha Wildner #define __ACLINUXEX_H__
1545f39c7e7SSascha Wildner 
1555f39c7e7SSascha Wildner #ifdef __KERNEL__
1565f39c7e7SSascha Wildner 
15779eafdd7SSascha Wildner #ifndef ACPI_USE_NATIVE_DIVIDE
15879eafdd7SSascha Wildner 
15979eafdd7SSascha Wildner #ifndef ACPI_DIV_64_BY_32
16079eafdd7SSascha Wildner #define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
16179eafdd7SSascha Wildner     do { \
16279eafdd7SSascha Wildner         UINT64 (__n) = ((UINT64) n_hi) << 32 | (n_lo); \
16379eafdd7SSascha Wildner         (r32) = do_div ((__n), (d32)); \
16479eafdd7SSascha Wildner         (q32) = (UINT32) (__n); \
16579eafdd7SSascha Wildner     } while (0)
16679eafdd7SSascha Wildner #endif
16779eafdd7SSascha Wildner 
16879eafdd7SSascha Wildner #ifndef ACPI_SHIFT_RIGHT_64
16979eafdd7SSascha Wildner #define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
17079eafdd7SSascha Wildner     do { \
17179eafdd7SSascha Wildner         (n_lo) >>= 1; \
17279eafdd7SSascha Wildner         (n_lo) |= (((n_hi) & 1) << 31); \
17379eafdd7SSascha Wildner         (n_hi) >>= 1; \
17479eafdd7SSascha Wildner     } while (0)
17579eafdd7SSascha Wildner #endif
17679eafdd7SSascha Wildner 
17779eafdd7SSascha Wildner #endif
17879eafdd7SSascha Wildner 
1795f39c7e7SSascha Wildner /*
1805f39c7e7SSascha Wildner  * Overrides for in-kernel ACPICA
1815f39c7e7SSascha Wildner  */
182277350a0SSascha Wildner ACPI_STATUS ACPI_INIT_FUNCTION AcpiOsInitialize (
1835f39c7e7SSascha Wildner     void);
1845f39c7e7SSascha Wildner 
1855f39c7e7SSascha Wildner ACPI_STATUS AcpiOsTerminate (
1865f39c7e7SSascha Wildner     void);
1875f39c7e7SSascha Wildner 
1885f39c7e7SSascha Wildner /*
1895f39c7e7SSascha Wildner  * The irqs_disabled() check is for resume from RAM.
1905f39c7e7SSascha Wildner  * Interrupts are off during resume, just like they are for boot.
1915f39c7e7SSascha Wildner  * However, boot has  (system_state != SYSTEM_RUNNING)
1925f39c7e7SSascha Wildner  * to quiet __might_sleep() in kmalloc() and resume does not.
1935f39c7e7SSascha Wildner  */
1945f39c7e7SSascha Wildner static inline void *
AcpiOsAllocate(ACPI_SIZE Size)1955f39c7e7SSascha Wildner AcpiOsAllocate (
1965f39c7e7SSascha Wildner     ACPI_SIZE               Size)
1975f39c7e7SSascha Wildner {
1985f39c7e7SSascha Wildner     return kmalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
1995f39c7e7SSascha Wildner }
2005f39c7e7SSascha Wildner 
2015f39c7e7SSascha Wildner static inline void *
AcpiOsAllocateZeroed(ACPI_SIZE Size)2025f39c7e7SSascha Wildner AcpiOsAllocateZeroed (
2035f39c7e7SSascha Wildner     ACPI_SIZE               Size)
2045f39c7e7SSascha Wildner {
2055f39c7e7SSascha Wildner     return kzalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
2065f39c7e7SSascha Wildner }
2075f39c7e7SSascha Wildner 
2085f39c7e7SSascha Wildner static inline void
AcpiOsFree(void * Memory)2095f39c7e7SSascha Wildner AcpiOsFree (
2105f39c7e7SSascha Wildner     void                   *Memory)
2115f39c7e7SSascha Wildner {
2125f39c7e7SSascha Wildner     kfree (Memory);
2135f39c7e7SSascha Wildner }
2145f39c7e7SSascha Wildner 
2155f39c7e7SSascha Wildner static inline void *
AcpiOsAcquireObject(ACPI_CACHE_T * Cache)2165f39c7e7SSascha Wildner AcpiOsAcquireObject (
2175f39c7e7SSascha Wildner     ACPI_CACHE_T           *Cache)
2185f39c7e7SSascha Wildner {
2195f39c7e7SSascha Wildner     return kmem_cache_zalloc (Cache,
2205f39c7e7SSascha Wildner         irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL);
2215f39c7e7SSascha Wildner }
2225f39c7e7SSascha Wildner 
2235f39c7e7SSascha Wildner static inline ACPI_THREAD_ID
AcpiOsGetThreadId(void)2245f39c7e7SSascha Wildner AcpiOsGetThreadId (
2255f39c7e7SSascha Wildner     void)
2265f39c7e7SSascha Wildner {
2275f39c7e7SSascha Wildner     return (ACPI_THREAD_ID) (unsigned long) current;
2285f39c7e7SSascha Wildner }
2295f39c7e7SSascha Wildner 
2305f39c7e7SSascha Wildner /*
2315f39c7e7SSascha Wildner  * When lockdep is enabled, the spin_lock_init() macro stringifies it's
2325f39c7e7SSascha Wildner  * argument and uses that as a name for the lock in debugging.
2335f39c7e7SSascha Wildner  * By executing spin_lock_init() in a macro the key changes from "lock" for
2345f39c7e7SSascha Wildner  * all locks to the name of the argument of acpi_os_create_lock(), which
2355f39c7e7SSascha Wildner  * prevents lockdep from reporting false positives for ACPICA locks.
2365f39c7e7SSascha Wildner  */
2375f39c7e7SSascha Wildner #define AcpiOsCreateLock(__Handle) \
2385f39c7e7SSascha Wildner     ({ \
2395f39c7e7SSascha Wildner         spinlock_t *Lock = ACPI_ALLOCATE(sizeof(*Lock)); \
2405f39c7e7SSascha Wildner         if (Lock) { \
2415f39c7e7SSascha Wildner             *(__Handle) = Lock; \
2425f39c7e7SSascha Wildner             spin_lock_init(*(__Handle)); \
2435f39c7e7SSascha Wildner         } \
2445f39c7e7SSascha Wildner         Lock ? AE_OK : AE_NO_MEMORY; \
2455f39c7e7SSascha Wildner     })
2465f39c7e7SSascha Wildner 
247820c5b08SSascha Wildner static inline BOOLEAN
AcpiOsReadable(void * Pointer,ACPI_SIZE Length)248820c5b08SSascha Wildner AcpiOsReadable (
249820c5b08SSascha Wildner     void                    *Pointer,
250820c5b08SSascha Wildner     ACPI_SIZE               Length)
251820c5b08SSascha Wildner {
252820c5b08SSascha Wildner     return TRUE;
253820c5b08SSascha Wildner }
254820c5b08SSascha Wildner 
25538b5d46cSSascha Wildner static inline ACPI_STATUS
AcpiOsInitializeDebugger(void)25638b5d46cSSascha Wildner AcpiOsInitializeDebugger (
25738b5d46cSSascha Wildner     void)
25838b5d46cSSascha Wildner {
25938b5d46cSSascha Wildner     return AE_OK;
26038b5d46cSSascha Wildner }
26138b5d46cSSascha Wildner 
26238b5d46cSSascha Wildner static inline void
AcpiOsTerminateDebugger(void)26338b5d46cSSascha Wildner AcpiOsTerminateDebugger (
26438b5d46cSSascha Wildner     void)
26538b5d46cSSascha Wildner {
26638b5d46cSSascha Wildner     return;
26738b5d46cSSascha Wildner }
26838b5d46cSSascha Wildner 
269820c5b08SSascha Wildner 
2705f39c7e7SSascha Wildner /*
2715f39c7e7SSascha Wildner  * OSL interfaces added by Linux
2725f39c7e7SSascha Wildner  */
2735f39c7e7SSascha Wildner 
2745f39c7e7SSascha Wildner #endif /* __KERNEL__ */
2755f39c7e7SSascha Wildner 
2765f39c7e7SSascha Wildner #endif /* __ACLINUXEX_H__ */
277