1/*
2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31
32#ifndef	_I386_MISC_PROTOS_H_
33#define	_I386_MISC_PROTOS_H_
34
35#include <machine/thread.h>
36
37struct boot_args;
38struct cpu_data;
39
40extern	boolean_t virtualized;
41
42extern void		vstart(vm_offset_t);
43extern void		i386_init(void);
44extern void		x86_init_wrapper(uintptr_t, uintptr_t) __attribute__((noreturn));
45extern void		i386_vm_init(
46				uint64_t,
47				boolean_t,
48				struct boot_args *);
49#ifdef __i386__
50extern void		cpu_IA32e_enable(struct cpu_data *);
51extern void		cpu_IA32e_disable(struct cpu_data *);
52extern void		ml_load_desc64(void);
53extern void		ml_64bit_lldt(int);
54#endif
55
56#if NCOPY_WINDOWS > 0
57extern void             cpu_userwindow_init(int);
58extern void             cpu_physwindow_init(int);
59#endif
60
61extern void		machine_startup(void);
62
63extern void		get_root_device(void);
64extern void		picinit(void);
65extern void		interrupt_processor(
66				int		cpu);
67extern void		mp_probe_cpus(void);
68extern void		panic_io_port_read(void);
69
70extern void		remote_kdb(void);
71extern void		clear_kdb_intr(void);
72extern void		cpu_init(void);
73#ifdef __i386__
74extern void		cpu_shutdown(void);
75#endif
76extern void		fix_desc(
77				void		* desc,
78				int		num_desc);
79extern void		fix_desc64(
80				void		* desc,
81				int		num_desc);
82extern void		cnpollc(
83				boolean_t	on);
84extern void		form_pic_mask(void);
85extern void		intnull(
86				int		unit);
87extern char *		i386_boot_info(
88				char		*buf,
89				vm_size_t	buf_len);
90
91extern void		blkclr(
92			       const char	*from,
93			       int		nbytes);
94
95#ifdef __i386__
96extern unsigned int	div_scale(
97				unsigned int	dividend,
98				unsigned int	divisor,
99				unsigned int	*scale);
100
101extern unsigned int	mul_scale(
102				unsigned int	multiplicand,
103				unsigned int	multiplier,
104				unsigned int	*scale);
105#endif
106
107/* Move arbitrarily-aligned data from one physical address to another */
108extern void bcopy_phys(addr64_t from, addr64_t to, vm_size_t nbytes);
109
110/* allow a function to get a quick virtual mapping of a physical page */
111extern int apply_func_phys(addr64_t src64, vm_size_t bytes, int (*func)(void * buffer, vm_size_t bytes, void * arg), void * arg);
112
113extern void ml_copy_phys(addr64_t, addr64_t, vm_size_t);
114
115/* Flush all cachelines for a page. */
116extern void cache_flush_page_phys(ppnum_t pa);
117
118/* Flushing for incoherent I/O */
119extern void dcache_incoherent_io_flush64(addr64_t pa, unsigned int count);
120extern void dcache_incoherent_io_store64(addr64_t pa, unsigned int count);
121
122
123extern processor_t	cpu_processor_alloc(boolean_t is_boot_cpu);
124extern void		cpu_processor_free(processor_t proc);
125
126extern void		*chudxnu_cpu_alloc(boolean_t is_boot_cpu);
127extern void		chudxnu_cpu_free(void *);
128
129extern void		sysclk_gettime_interrupts_disabled(
130				mach_timespec_t *cur_time);
131
132extern void rtc_nanotime_init_commpage(void);
133
134extern void	rtc_sleep_wakeup(uint64_t base);
135
136extern void	rtc_timer_start(void);
137
138extern void	rtc_clock_stepping(
139			uint32_t new_frequency,
140			uint32_t old_frequency);
141extern void	rtc_clock_stepped(
142			uint32_t new_frequency,
143			uint32_t old_frequency);
144extern void	rtc_clock_napped(uint64_t, uint64_t);
145extern void	rtc_clock_adjust(uint64_t);
146
147extern void     pmap_lowmem_finalize(void);
148
149thread_t Switch_context(thread_t, thread_continue_t, thread_t);
150thread_t Shutdown_context(thread_t thread, void (*doshutdown)(processor_t),processor_t  processor);
151
152#ifdef __x86_64__
153uint64_t x86_64_pre_sleep(void);
154void x86_64_post_sleep(uint64_t new_cr3);
155#endif
156
157boolean_t
158debug_state_is_valid32(x86_debug_state32_t *ds);
159
160boolean_t
161debug_state_is_valid64(x86_debug_state64_t *ds);
162
163void
164copy_debug_state32(x86_debug_state32_t *src, x86_debug_state32_t *target, boolean_t all);
165
166void
167copy_debug_state64(x86_debug_state64_t *src, x86_debug_state64_t *target, boolean_t all);
168
169extern void act_machine_switch_pcb(thread_t old, thread_t new);
170
171/* Fast-restart parameters */
172#define FULL_SLAVE_INIT	(NULL)
173#define FAST_SLAVE_INIT	((void *)(uintptr_t)1)
174
175uint64_t ml_early_random(void);
176void cpu_pmc_control(void *);
177#endif /* _I386_MISC_PROTOS_H_ */
178