]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu.c
3ef513a270e89fd9299727f637c91acd8367732c
[apple/xnu.git] / osfmk / i386 / cpu.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * File: i386/cpu.c
27 *
28 * cpu specific routines
29 */
30
31 #include <kern/machine.h>
32 #include <kern/misc_protos.h>
33 #include <kern/cpu_data.h>
34 #include <kern/cpu_number.h>
35 #include <kern/processor.h>
36 #include <mach/processor_info.h>
37 #include <i386/machine_cpu.h>
38 #include <i386/machine_routines.h>
39 #include <i386/mp_desc.h>
40
41 cpu_data_t cpu_data[NCPUS];
42 int real_ncpus = 0;
43 int wncpu = NCPUS;
44
45 /*ARGSUSED*/
46 kern_return_t
47 cpu_control(
48 int slot_num,
49 processor_info_t info,
50 unsigned int count)
51 {
52 printf("cpu_control not implemented\n");
53 return (KERN_FAILURE);
54 }
55
56 /*ARGSUSED*/
57 kern_return_t
58 cpu_info_count(
59 processor_flavor_t flavor,
60 unsigned int *count)
61 {
62 *count = 0;
63 return (KERN_FAILURE);
64 }
65
66 /*ARGSUSED*/
67 kern_return_t
68 cpu_info(
69 processor_flavor_t flavor,
70 int slot_num,
71 processor_info_t info,
72 unsigned int *count)
73 {
74 printf("cpu_info not implemented\n");
75 return (KERN_FAILURE);
76 }
77
78 void
79 cpu_sleep()
80 {
81 printf("cpu_sleep not implemented\n");
82 }
83
84 void
85 cpu_init()
86 {
87 int my_cpu = get_cpu_number();
88
89 machine_slot[my_cpu].is_cpu = TRUE;
90 machine_slot[my_cpu].running = TRUE;
91 #ifdef MACH_BSD
92 /* FIXME */
93 machine_slot[my_cpu].cpu_type = CPU_TYPE_I386;
94 machine_slot[my_cpu].cpu_subtype = CPU_SUBTYPE_PENTPRO;
95 #else
96 machine_slot[my_cpu].cpu_type = cpuid_cputype(0);
97 machine_slot[my_cpu].cpu_subtype = CPU_SUBTYPE_AT386;
98 #endif
99
100 #if NCPUS > 1
101 mp_desc_init(my_cpu);
102 #endif /* NCPUS */
103 }
104
105 kern_return_t
106 cpu_register(
107 int *target_cpu)
108 {
109 int cpu;
110
111 if (real_ncpus == 0) {
112 /*
113 * Special case for the boot processor,
114 * it has been pre-registered by cpu_init();
115 */
116 *target_cpu = 0;
117 real_ncpus++;
118 return KERN_SUCCESS;
119 }
120
121 /*
122 * TODO:
123 * - Run cpu_register() in exclusion mode
124 */
125
126 *target_cpu = -1;
127 for(cpu=0; cpu < wncpu; cpu++) {
128 if(!machine_slot[cpu].is_cpu) {
129 machine_slot[cpu].is_cpu = TRUE;
130 #ifdef MACH_BSD
131 /* FIXME */
132 machine_slot[cpu].cpu_type = CPU_TYPE_I386;
133 machine_slot[cpu].cpu_subtype = CPU_SUBTYPE_PENTPRO;
134 #else
135 machine_slot[cpu].cpu_type = cpuid_cputype(0);
136 machine_slot[cpu].cpu_subtype = CPU_SUBTYPE_AT386;
137 #endif
138 *target_cpu = cpu;
139 break;
140 }
141 }
142
143 if (*target_cpu != -1) {
144 real_ncpus++;
145 return KERN_SUCCESS;
146 } else
147 return KERN_FAILURE;
148 }
149
150 kern_return_t
151 cpu_start(
152 int cpu)
153 {
154 kern_return_t ret;
155
156 if (cpu == cpu_number()) {
157 PE_cpu_machine_init(cpu_data[cpu].cpu_id, TRUE);
158 ml_init_interrupt();
159 cpu_data[cpu].cpu_status = 1;
160 return KERN_SUCCESS;
161 } else {
162 /*
163 * Should call out through PE.
164 * But take the shortcut here.
165 */
166 ret = intel_startCPU(cpu);
167 return(ret);
168 }
169 }
170
171 void
172 cpu_machine_init(
173 void)
174 {
175 int cpu;
176
177 cpu = get_cpu_number();
178 PE_cpu_machine_init(cpu_data[cpu].cpu_id, TRUE);
179 ml_init_interrupt();
180 cpu_data[cpu].cpu_status = 1;
181 }
182