ReactOS 0.4.16-dev-1946-g52006dd
kernel_api.h
Go to the documentation of this file.
1#pragma once
2
3#include <uacpi/types.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10// Returns the PHYSICAL address of the RSDP structure via *out_rsdp_address.
12
13/*
14 * Map a physical memory range starting at 'addr' with length 'len', and return
15 * a virtual address that can be used to access it.
16 *
17 * NOTE: 'addr' may be misaligned, in this case the host is expected to round it
18 * down to the nearest page-aligned boundary and map that, while making
19 * sure that at least 'len' bytes are still mapped starting at 'addr'. The
20 * return value preserves the misaligned offset.
21 *
22 * Example for uacpi_kernel_map(0x1ABC, 0xF00):
23 * 1. Round down the 'addr' we got to the nearest page boundary.
24 * Considering a PAGE_SIZE of 4096 (or 0x1000), 0x1ABC rounded down
25 * is 0x1000, offset within the page is 0x1ABC - 0x1000 => 0xABC
26 * 2. Requested 'len' is 0xF00 bytes, but we just rounded the address
27 * down by 0xABC bytes, so add those on top. 0xF00 + 0xABC => 0x19BC
28 * 3. Round up the final 'len' to the nearest PAGE_SIZE boundary, in
29 * this case 0x19BC is 0x2000 bytes (2 pages if PAGE_SIZE is 4096)
30 * 4. Call the VMM to map the aligned address 0x1000 (from step 1)
31 * with length 0x2000 (from step 3). Let's assume the returned
32 * virtual address for the mapping is 0xF000.
33 * 5. Add the original offset within page 0xABC (from step 1) to the
34 * resulting virtual address 0xF000 + 0xABC => 0xFABC. Return it
35 * to uACPI.
36 */
38
39/*
40 * Unmap a virtual memory range at 'addr' with a length of 'len' bytes.
41 *
42 * NOTE: 'addr' may be misaligned, see the comment above 'uacpi_kernel_map'.
43 * Similar steps to uacpi_kernel_map can be taken to retrieve the
44 * virtual address originally returned by the VMM for this mapping
45 * as well as its true length.
46 */
48
49#ifndef UACPI_FORMATTED_LOGGING
51#else
54void uacpi_kernel_vlog(uacpi_log_level, const uacpi_char*, uacpi_va_list);
55#endif
56
57/*
58 * Only the above ^^^ API may be used by early table access and
59 * UACPI_BAREBONES_MODE.
60 */
61#ifndef UACPI_BAREBONES_MODE
62
63/*
64 * Convenience initialization/deinitialization hooks that will be called by
65 * uACPI automatically when appropriate if compiled-in.
66 */
67#ifdef UACPI_KERNEL_INITIALIZATION
68/*
69 * This API is invoked for each initialization level so that appropriate parts
70 * of the host kernel and/or glue code can be initialized at different stages.
71 *
72 * uACPI API that triggers calls to uacpi_kernel_initialize and the respective
73 * 'current_init_lvl' passed to the hook at that stage:
74 * 1. uacpi_initialize() -> UACPI_INIT_LEVEL_EARLY
75 * 2. uacpi_namespace_load() -> UACPI_INIT_LEVEL_SUBSYSTEM_INITIALIZED
76 * 3. (start of) uacpi_namespace_initialize() -> UACPI_INIT_LEVEL_NAMESPACE_LOADED
77 * 4. (end of) uacpi_namespace_initialize() -> UACPI_INIT_LEVEL_NAMESPACE_INITIALIZED
78 */
79uacpi_status uacpi_kernel_initialize(uacpi_init_level current_init_lvl);
80void uacpi_kernel_deinitialize(void);
81#endif
82
83/*
84 * Open a PCI device at 'address' for reading & writing.
85 *
86 * Note that this must be able to open any arbitrary PCI device, not just those
87 * detected during kernel PCI enumeration, since the following pattern is
88 * relatively common in AML firmware:
89 * Device (THC0)
90 * {
91 * // Device at 00:10.06
92 * Name (_ADR, 0x00100006) // _ADR: Address
93 *
94 * OperationRegion (THCR, PCI_Config, Zero, 0x0100)
95 * Field (THCR, ByteAcc, NoLock, Preserve)
96 * {
97 * // Vendor ID field in the PCI configuration space
98 * VDID, 32
99 * }
100 *
101 * // Check if the device at 00:10.06 actually exists, that is reading
102 * // from its configuration space returns something other than 0xFFs.
103 * If ((VDID != 0xFFFFFFFF))
104 * {
105 * // Actually create the rest of the device's body if it's present
106 * // in the system, otherwise skip it.
107 * }
108 * }
109 *
110 * The handle returned via 'out_handle' is used to perform IO on the
111 * configuration space of the device.
112 */
115);
117
118/*
119 * Read & write the configuration space of a previously open PCI device.
120 */
123);
126);
129);
130
133);
136);
139);
140
141/*
142 * Map a SystemIO address at [base, base + len) and return a kernel-implemented
143 * handle that can be used for reading and writing the IO range.
144 *
145 * NOTE: The x86 architecture uses the in/out family of instructions
146 * to access the SystemIO address space.
147 */
150);
152
153/*
154 * Read/Write the IO range mapped via uacpi_kernel_io_map
155 * at a 0-based 'offset' within the range.
156 *
157 * NOTE:
158 * The x86 architecture uses the in/out family of instructions
159 * to access the SystemIO address space.
160 *
161 * You are NOT allowed to break e.g. a 4-byte access into four 1-byte accesses.
162 * Hardware ALWAYS expects accesses to be of the exact width.
163 */
166);
169);
172);
173
176);
179);
182);
183
184/*
185 * Allocate a block of memory of 'size' bytes.
186 * The contents of the allocated memory are unspecified.
187 */
189
190#ifdef UACPI_NATIVE_ALLOC_ZEROED
191/*
192 * Allocate a block of memory of 'size' bytes.
193 * The returned memory block is expected to be zero-filled.
194 */
196#endif
197
198/*
199 * Free a previously allocated memory block.
200 *
201 * 'mem' might be a NULL pointer. In this case, the call is assumed to be a
202 * no-op.
203 *
204 * An optionally enabled 'size_hint' parameter contains the size of the original
205 * allocation. Note that in some scenarios this incurs additional cost to
206 * calculate the object size.
207 */
208#ifndef UACPI_SIZED_FREES
209void uacpi_kernel_free(void *mem);
210#else
211void uacpi_kernel_free(void *mem, uacpi_size size_hint);
212#endif
213
214/*
215 * Returns the number of nanosecond ticks elapsed since boot,
216 * strictly monotonic.
217 */
219
220/*
221 * Spin for N microseconds.
222 */
224
225/*
226 * Sleep for N milliseconds.
227 */
229
230/*
231 * Create/free an opaque non-recursive kernel mutex object.
232 */
235
236/*
237 * Create/free an opaque kernel (semaphore-like) event object.
238 */
241
242/*
243 * Returns a unique identifier of the currently executing thread.
244 *
245 * The returned thread id cannot be UACPI_THREAD_ID_NONE.
246 */
248
249/*
250 * Try to acquire the mutex with a millisecond timeout.
251 *
252 * The timeout value has the following meanings:
253 * 0x0000 - Attempt to acquire the mutex once, in a non-blocking manner
254 * 0x0001...0xFFFE - Attempt to acquire the mutex for at least 'timeout'
255 * milliseconds
256 * 0xFFFF - Infinite wait, block until the mutex is acquired
257 *
258 * The following are possible return values:
259 * 1. UACPI_STATUS_OK - successful acquire operation
260 * 2. UACPI_STATUS_TIMEOUT - timeout reached while attempting to acquire (or the
261 * single attempt to acquire was not successful for
262 * calls with timeout=0)
263 * 3. Any other value - signifies a host internal error and is treated as such
264 */
267
268/*
269 * Try to wait for an event (counter > 0) with a millisecond timeout.
270 * A timeout value of 0xFFFF implies infinite wait.
271 *
272 * The internal counter is decremented by 1 if wait was successful.
273 *
274 * A successful wait is indicated by returning UACPI_TRUE.
275 */
277
278/*
279 * Signal the event object by incrementing its internal counter by 1.
280 *
281 * This function may be used in interrupt contexts.
282 */
284
285/*
286 * Reset the event counter to 0.
287 */
289
290/*
291 * Handle a firmware request.
292 *
293 * Currently either a Breakpoint or Fatal operators.
294 */
296
297/*
298 * Install an interrupt handler at 'irq', 'ctx' is passed to the provided
299 * handler for every invocation.
300 *
301 * 'out_irq_handle' is set to a kernel-implemented value that can be used to
302 * refer to this handler from other API.
303 */
306 uacpi_handle *out_irq_handle
307);
308
309/*
310 * Uninstall an interrupt handler. 'irq_handle' is the value returned via
311 * 'out_irq_handle' during installation.
312 */
315);
316
317/*
318 * Create/free a kernel spinlock object.
319 *
320 * Unlike other types of locks, spinlocks may be used in interrupt contexts.
321 */
324
325/*
326 * Lock/unlock helpers for spinlocks.
327 *
328 * These are expected to disable interrupts, returning the previous state of cpu
329 * flags, that can be used to possibly re-enable interrupts if they were enabled
330 * before.
331 *
332 * Note that lock is infalliable.
333 */
336
337typedef enum uacpi_work_type {
338 /*
339 * Schedule a GPE handler method for execution.
340 * This should be scheduled to run on CPU0 to avoid potential SMI-related
341 * firmware bugs.
342 */
344
345 /*
346 * Schedule a Notify(device) firmware request for execution.
347 * This can run on any CPU.
348 */
351
353
354/*
355 * Schedules deferred work for execution.
356 * Might be invoked from an interrupt context.
357 */
360);
361
362/*
363 * Waits for two types of work to finish:
364 * 1. All in-flight interrupts installed via uacpi_kernel_install_interrupt_handler
365 * 2. All work scheduled via uacpi_kernel_schedule_work
366 *
367 * Note that the waits must be done in this order specifically.
368 */
370
371#endif // !UACPI_BAREBONES_MODE
372
373#ifdef __cplusplus
374}
375#endif
unsigned long uacpi_cpu_flags
Definition: arch_helpers.h:13
#define uacpi_kernel_alloc_zeroed
Definition: stdlib.h:127
uacpi_log_level
Definition: log.h:7
#define UACPI_PRINTF_DECL(fmt_idx, args_idx)
Definition: compiler.h:66
size_t uacpi_size
Definition: types.h:37
uint32_t uacpi_u32
Definition: types.h:21
bool uacpi_bool
Definition: types.h:31
va_list uacpi_va_list
Definition: types.h:39
uint64_t uacpi_u64
Definition: types.h:22
char uacpi_char
Definition: types.h:44
uint16_t uacpi_u16
Definition: types.h:20
uint8_t uacpi_u8
Definition: types.h:19
uacpi_status
Definition: status.h:10
uacpi_u64 uacpi_io_addr
Definition: types.h:18
void * uacpi_handle
Definition: types.h:21
uacpi_u64 uacpi_phys_addr
Definition: types.h:17
uacpi_init_level
Definition: types.h:58
uacpi_interrupt_ret(* uacpi_interrupt_handler)(uacpi_handle)
Definition: types.h:538
unsigned char irq
Definition: dsp.h:13
GLuint address
Definition: glext.h:9393
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
uacpi_status uacpi_kernel_io_map(uacpi_io_addr base, uacpi_size len, uacpi_handle *out_handle)
Definition: uacpiosl.c:165
void uacpi_kernel_free_event(uacpi_handle)
Definition: uacpiosl.c:60
uacpi_status uacpi_kernel_pci_write16(uacpi_handle device, uacpi_size offset, uacpi_u16 value)
Definition: uacpiosl.c:285
void uacpi_kernel_pci_device_close(uacpi_handle)
Definition: uacpiosl.c:251
uacpi_status uacpi_kernel_pci_read8(uacpi_handle device, uacpi_size offset, uacpi_u8 *value)
Definition: uacpiosl.c:257
uacpi_bool uacpi_kernel_wait_for_event(uacpi_handle, uacpi_u16)
Definition: uacpiosl.c:66
void * uacpi_kernel_alloc(uacpi_size size)
Definition: uacpiosl.c:111
uacpi_status uacpi_kernel_io_write8(uacpi_handle, uacpi_size offset, uacpi_u8 in_value)
Definition: uacpiosl.c:320
uacpi_status uacpi_kernel_wait_for_work_completion(void)
Definition: uacpiosl.c:235
uacpi_status uacpi_kernel_schedule_work(uacpi_work_type, uacpi_work_handler, uacpi_handle ctx)
Definition: uacpiosl.c:228
void uacpi_kernel_reset_event(uacpi_handle)
Definition: uacpiosl.c:79
void(* uacpi_work_handler)(uacpi_handle)
Definition: kernel_api.h:352
uacpi_status uacpi_kernel_uninstall_interrupt_handler(uacpi_interrupt_handler, uacpi_handle irq_handle)
Definition: uacpiosl.c:221
void uacpi_kernel_stall(uacpi_u8 usec)
Definition: uacpiosl.c:42
uacpi_handle uacpi_kernel_create_mutex(void)
Definition: uacpiosl.c:139
uacpi_status uacpi_kernel_install_interrupt_handler(uacpi_u32 irq, uacpi_interrupt_handler, uacpi_handle ctx, uacpi_handle *out_irq_handle)
Definition: uacpiosl.c:212
void uacpi_kernel_free_mutex(uacpi_handle)
Definition: uacpiosl.c:146
uacpi_status uacpi_kernel_pci_read16(uacpi_handle device, uacpi_size offset, uacpi_u16 *value)
Definition: uacpiosl.c:264
void uacpi_kernel_sleep(uacpi_u64 msec)
Definition: uacpiosl.c:47
uacpi_status uacpi_kernel_io_read32(uacpi_handle, uacpi_size offset, uacpi_u32 *out_value)
Definition: uacpiosl.c:313
uacpi_status uacpi_kernel_pci_read32(uacpi_handle device, uacpi_size offset, uacpi_u32 *value)
Definition: uacpiosl.c:271
uacpi_status uacpi_kernel_io_write32(uacpi_handle, uacpi_size offset, uacpi_u32 in_value)
Definition: uacpiosl.c:334
uacpi_handle uacpi_kernel_create_event(void)
Definition: uacpiosl.c:53
uacpi_thread_id uacpi_kernel_get_thread_id(void)
Definition: uacpiosl.c:184
void uacpi_kernel_free(void *mem)
Definition: uacpiosl.c:126
uacpi_status uacpi_kernel_io_read8(uacpi_handle, uacpi_size offset, uacpi_u8 *out_value)
Definition: uacpiosl.c:299
uacpi_status uacpi_kernel_pci_device_open(uacpi_pci_address address, uacpi_handle *out_handle)
Definition: uacpiosl.c:242
uacpi_work_type
Definition: kernel_api.h:337
@ UACPI_WORK_GPE_EXECUTION
Definition: kernel_api.h:343
@ UACPI_WORK_NOTIFICATION
Definition: kernel_api.h:349
uacpi_u64 uacpi_kernel_get_nanoseconds_since_boot(void)
Definition: uacpiosl.c:35
uacpi_status uacpi_kernel_handle_firmware_request(uacpi_firmware_request *)
Definition: uacpiosl.c:177
uacpi_status uacpi_kernel_pci_write8(uacpi_handle device, uacpi_size offset, uacpi_u8 value)
Definition: uacpiosl.c:278
uacpi_handle uacpi_kernel_create_spinlock(void)
Definition: uacpiosl.c:85
void uacpi_kernel_release_mutex(uacpi_handle)
Definition: uacpiosl.c:159
void uacpi_kernel_unmap(void *addr, uacpi_size len)
Definition: uacpiosl.c:198
uacpi_status uacpi_kernel_io_write16(uacpi_handle, uacpi_size offset, uacpi_u16 in_value)
Definition: uacpiosl.c:327
uacpi_status uacpi_kernel_io_read16(uacpi_handle, uacpi_size offset, uacpi_u16 *out_value)
Definition: uacpiosl.c:306
uacpi_status uacpi_kernel_acquire_mutex(uacpi_handle, uacpi_u16)
Definition: uacpiosl.c:152
void * uacpi_kernel_map(uacpi_phys_addr addr, uacpi_size len)
Definition: uacpiosl.c:191
void uacpi_kernel_io_unmap(uacpi_handle handle)
Definition: uacpiosl.c:171
uacpi_status uacpi_kernel_pci_write32(uacpi_handle device, uacpi_size offset, uacpi_u32 value)
Definition: uacpiosl.c:292
uacpi_status uacpi_kernel_get_rsdp(uacpi_phys_addr *out_rsdp_address)
Definition: uacpiosl.c:204
void uacpi_kernel_signal_event(uacpi_handle)
Definition: uacpiosl.c:73
void uacpi_kernel_free_spinlock(uacpi_handle)
Definition: uacpiosl.c:92
void uacpi_kernel_log(uacpi_log_level, const uacpi_char *)
Definition: uacpiosl.c:18
uacpi_cpu_flags uacpi_kernel_lock_spinlock(uacpi_handle)
Definition: uacpiosl.c:98
void uacpi_kernel_unlock_spinlock(uacpi_handle, uacpi_cpu_flags)
Definition: uacpiosl.c:105
Definition: devices.h:37
Definition: mem.c:349
Definition: pdh_main.c:96
#define const
Definition: zconf.h:233