3 * Copyright (c) 2009 Apple Inc. All rights reserved.
5 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. The rights granted to you under the License
11 * may not be used to create, or enable the creation or redistribution of,
12 * unlawful or unlicensed copies of an Apple operating system, or to
13 * circumvent, violate, or enable the circumvention or violation of, any
14 * terms of an Apple operating system software license agreement.
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this file.
19 * The Original Code and all software distributed under the License are
20 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
21 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
22 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
24 * Please see the License for the specific language governing rights and
25 * limitations under the License.
27 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _I386_PAL_ROUTINES_H
30 #define _I386_PAL_ROUTINES_H
33 #include <mach/kern_return.h>
34 #include <mach/mach_types.h>
36 #if defined(__cplusplus)
40 /* PAL routines exported to kexts */
43 * Load registers with these values. In 32-bit mode,
44 * only the low-order half is loaded (if applicable)
46 struct pal_efi_registers
{
55 * Load registers and stack with these values before
56 * executing "call" instruction
59 pal_efi_call_in_64bit_mode(uint64_t func
,
60 struct pal_efi_registers
*efi_reg
,
62 size_t stack_contents_size
, /* 16-byte multiple */
63 uint64_t *efi_status
);
66 pal_efi_call_in_32bit_mode(uint32_t func
,
67 struct pal_efi_registers
*efi_reg
,
69 size_t stack_contents_size
, /* 16-byte multiple */
70 uint32_t *efi_status
);
72 /* Go into ACPI sleep */
74 boolean_t
pal_machine_sleep(uint8_t type_a
,
76 uint32_t bit_position
,
77 uint32_t disable_mask
,
78 uint32_t enable_mask
);
80 /* xnu internal PAL routines */
81 #ifdef XNU_KERNEL_PRIVATE
83 /* Define any PAL-specific types for x86 */
85 typedef uint32_t pal_cr_t
;
87 typedef uint64_t pal_cr_t
;
90 struct pal_cpu_data
; /* Defined per-platform */
91 struct pal_pcb
; /* Defined per-platform */
92 struct pal_apic_table
; /* Defined per-platform */
94 /* For use by APIC kext */
95 extern struct pal_apic_table
*apic_table
;
97 /* serial / debug output routines */
98 extern int pal_serial_init(void);
99 extern void pal_serial_putc(char);
100 extern int pal_serial_getc(void);
102 /* Generic I386 PAL functions go here */
103 extern void pal_i386_init(void);
104 extern void pal_set_signal_delivery(thread_t
);
106 /* Get values for cr0..4 */
107 extern void pal_get_control_registers( pal_cr_t
*cr0
, pal_cr_t
*cr2
,
108 pal_cr_t
*cr3
, pal_cr_t
*cr4
);
110 /* Debug hook invoked in the page-fault path */
111 extern void pal_dbg_page_fault( thread_t thread
, user_addr_t vadddr
,
114 /* Set a task's name in the platform kernel debugger */
115 extern void pal_dbg_set_task_name( task_t task
);
117 /* wind-back to the start of a system call */
118 void pal_syscall_restart(thread_t thread
, x86_saved_state_t
*state
);
120 /* Hook for non-vfork exec */
121 void pal_execve_return(thread_t thread
);
123 /* Called by thread_terminate_self() */
124 void pal_thread_terminate_self(thread_t thread
);
126 /* Called by ast_check() */
127 void pal_ast_check(thread_t thread
);
129 /* Called by sync_iss_to_iks */
130 extern void pal_get_kern_regs( x86_saved_state_t
*state
);
132 /* Called by load_machfile */
133 void pal_switch_pmap(thread_t
, pmap_t
, boolean_t
);
136 * Platform-specific hlt/sti.
138 extern void pal_hlt(void);
139 extern void pal_sti(void);
140 extern void pal_cli(void);
143 * Mark in-memory thread register cache state validity.
145 typedef enum { DIRTY
, VALID
} pal_cache_state_t
;
146 void pal_register_cache_state(thread_t thread
, pal_cache_state_t state
);
149 /* Catch code running on the except thread that shouldn't be */
150 void pal_preemption_assert(void);
152 void hibernate_pal_prepare(void);
153 void pal_efi_hibernate_prepare(void);
155 /* Include a PAL-specific header, too, for xnu-internal overrides */
156 #include <i386/pal_native.h>
158 extern boolean_t virtualized
;
159 #define PAL_VIRTUALIZED_PROPERTY_VALUE 4
161 /* Allow for tricky IOKit property matching */
162 #define PAL_AICPM_PROPERTY_NAME "intel_cpupm_matching"
164 pal_get_resource_property(const char **property_name
, int *property_value
)
166 *property_name
= PAL_AICPM_PROPERTY_NAME
;
167 *property_value
= PAL_AICPM_PROPERTY_VALUE
;
169 *property_value
= PAL_VIRTUALIZED_PROPERTY_VALUE
;
172 /* assembly function to update TSC / timebase info */
173 extern void _pal_rtc_nanotime_store(
178 struct pal_rtc_nanotime
*dst
);
180 /* global nanotime info */
181 extern struct pal_rtc_nanotime pal_rtc_nanotime_info
;
183 #endif /* XNU_KERNEL_PRIVATE */
185 #if defined(__cplusplus)
189 #endif /* _I386_PAL_ROUTINES_H */