1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <stdbool.h>
8 #include <threads.h>
9 
10 #include <zircon/assert.h>
11 #include <zircon/syscalls.h>
12 #include <semaphore.h>
13 
14 /*
15  * Settings described in section 7 of
16  * https://acpica.org/sites/acpica/files/acpica-reference_17.pdf
17  */
18 
19 
20 #if __x86_64__
21 #define ACPI_MACHINE_WIDTH 64
22 #elif __x86__
23 #define ACPI_MACHINE_WIDTH 32
24 #define ACPI_USE_NATIVE_DIVIDE
25 #else
26 #error Unexpected architecture
27 #endif
28 
29 extern zx_handle_t root_resource_handle;
30 
31 // Make this a no-op.  The only codepath we use it for is ACPI poweroff, in
32 // which case we don't care about the cache state.
33 #define ACPI_FLUSH_CPU_CACHE()
34 
35 // Use the standard library headers
36 #define ACPI_USE_STANDARD_HEADERS
37 #define ACPI_USE_SYSTEM_CLIBRARY
38 
39 // Use the builtin cache implementation
40 #define ACPI_USE_LOCAL_CACHE
41 
42 #define ACPI_MUTEX_TYPE     ACPI_OSL_MUTEX
43 
44 // Specify the types Fuchsia uses for various common objects
45 #define ACPI_CPU_FLAGS int
46 #define ACPI_SPINLOCK mtx_t*
47 #define ACPI_MUTEX mtx_t*
48 #define ACPI_SEMAPHORE sem_t*
49 
50 // Borrowed from aclinuxex.h
51 
52 // Include the gcc header since we're compiling on gcc
53 #include "acgcc.h"
54 
55 __BEGIN_CDECLS
56 bool _acpica_acquire_global_lock(void *FacsPtr);
57 bool _acpica_release_global_lock(void *FacsPtr);
58 
59 void acpica_enable_noncontested_mode(void);
60 void acpica_disable_noncontested_mode(void);
61 __END_CDECLS
62 
63 #define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq) Acq = _acpica_acquire_global_lock(FacsPtr)
64 #define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) Pnd = _acpica_release_global_lock(FacsPtr)
65