]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cpu.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
8f6c56a5 11 *
6601e61a
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
21 */
22/*
23 * File: i386/cpu.c
24 *
25 * cpu specific routines
26 */
27
91447636 28#include <kern/kalloc.h>
1c79356b 29#include <kern/misc_protos.h>
91447636 30#include <kern/machine.h>
1c79356b 31#include <mach/processor_info.h>
91447636 32#include <i386/mp.h>
55e303ae
A
33#include <i386/machine_cpu.h>
34#include <i386/machine_routines.h>
91447636
A
35#include <i386/pmap.h>
36#include <i386/misc_protos.h>
37#include <i386/cpu_threads.h>
0c530ab8 38#include <i386/rtclock.h>
91447636 39#include <vm/vm_kern.h>
0c530ab8 40#include "cpuid.h"
1c79356b 41
91447636 42struct processor processor_master;
9bccf70c 43
1c79356b
A
44/*ARGSUSED*/
45kern_return_t
46cpu_control(
47 int slot_num,
48 processor_info_t info,
49 unsigned int count)
50{
91447636
A
51 printf("cpu_control(%d,0x%x,%d) not implemented\n",
52 slot_num, info, count);
1c79356b
A
53 return (KERN_FAILURE);
54}
55
56/*ARGSUSED*/
57kern_return_t
58cpu_info_count(
91447636
A
59 __unused processor_flavor_t flavor,
60 unsigned int *count)
1c79356b
A
61{
62 *count = 0;
63 return (KERN_FAILURE);
64}
65
66/*ARGSUSED*/
67kern_return_t
68cpu_info(
69 processor_flavor_t flavor,
70 int slot_num,
71 processor_info_t info,
72 unsigned int *count)
73{
91447636
A
74 printf("cpu_info(%d,%d,0x%x,0x%x) not implemented\n",
75 flavor, slot_num, info, count);
1c79356b
A
76 return (KERN_FAILURE);
77}
78
79void
91447636 80cpu_sleep(void)
1c79356b 81{
91447636 82 cpu_data_t *proc_info = current_cpu_datap();
55e303ae 83
0c530ab8
A
84 proc_info->cpu_running = FALSE;
85
91447636 86 PE_cpu_machine_quiesce(proc_info->cpu_id);
55e303ae 87
91447636 88 cpu_thread_halt();
55e303ae
A
89}
90
91447636
A
91void
92cpu_init(void)
55e303ae 93{
91447636 94 cpu_data_t *cdp = current_cpu_datap();
55e303ae 95
0c530ab8
A
96 cdp->cpu_type = cpuid_cputype();
97 cdp->cpu_subtype = cpuid_cpusubtype();
98
91447636 99 cdp->cpu_running = TRUE;
55e303ae
A
100}
101
102kern_return_t
103cpu_start(
104 int cpu)
105{
106 kern_return_t ret;
107
108 if (cpu == cpu_number()) {
91447636 109 cpu_machine_init();
55e303ae
A
110 return KERN_SUCCESS;
111 } else {
112 /*
113 * Should call out through PE.
114 * But take the shortcut here.
115 */
116 ret = intel_startCPU(cpu);
117 return(ret);
118 }
119}
120
91447636
A
121void
122cpu_exit_wait(
123 __unused int cpu)
124{
125}
126
55e303ae
A
127void
128cpu_machine_init(
129 void)
130{
0c530ab8 131 cpu_data_t *cdp = current_cpu_datap();
55e303ae 132
0c530ab8
A
133 PE_cpu_machine_init(cdp->cpu_id, !cdp->cpu_boot_complete);
134 cdp->cpu_boot_complete = TRUE;
135 cdp->cpu_running = TRUE;
3a60a9f5
A
136#if 0
137 if (cpu_datap(cpu)->hibernate)
138 {
139 cpu_datap(cpu)->hibernate = 0;
140 hibernate_machine_init();
141 }
142#endif
55e303ae 143 ml_init_interrupt();
55e303ae
A
144}
145
91447636
A
146processor_t
147cpu_processor_alloc(boolean_t is_boot_cpu)
148{
149 int ret;
150 processor_t proc;
151
152 if (is_boot_cpu)
153 return &processor_master;
154
155 ret = kmem_alloc(kernel_map, (vm_offset_t *) &proc, sizeof(*proc));
156 if (ret != KERN_SUCCESS)
157 return NULL;
158
159 bzero((void *) proc, sizeof(*proc));
160 return proc;
161}
162
163void
164cpu_processor_free(processor_t proc)
165{
166 if (proc != NULL && proc != &processor_master)
167 kfree((void *) proc, sizeof(*proc));
168}
169
170processor_t
171current_processor(void)
172{
173 return current_cpu_datap()->cpu_processor;
174}
175
176processor_t
177cpu_to_processor(
178 int cpu)
179{
180 return cpu_datap(cpu)->cpu_processor;
181}
182
183ast_t *
184ast_pending(void)
185{
186 return (&current_cpu_datap()->cpu_pending_ast);
187}
188
189cpu_type_t
190slot_type(
191 int slot_num)
192{
193 return (cpu_datap(slot_num)->cpu_type);
194}
195
196cpu_subtype_t
197slot_subtype(
198 int slot_num)
199{
200 return (cpu_datap(slot_num)->cpu_subtype);
201}
202
203cpu_threadtype_t
204slot_threadtype(
205 int slot_num)
206{
207 return (cpu_datap(slot_num)->cpu_threadtype);
208}
209
210cpu_type_t
211cpu_type(void)
212{
213 return (current_cpu_datap()->cpu_type);
214}
215
216cpu_subtype_t
217cpu_subtype(void)
218{
219 return (current_cpu_datap()->cpu_subtype);
220}
221
222cpu_threadtype_t
223cpu_threadtype(void)
224{
225 return (current_cpu_datap()->cpu_threadtype);
226}