]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu.c
xnu-517.7.7.tar.gz
[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 * 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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * File: i386/cpu.c
24 *
25 * cpu specific routines
26 */
27
28 #include <kern/machine.h>
29 #include <kern/misc_protos.h>
30 #include <kern/cpu_data.h>
31 #include <kern/cpu_number.h>
32 #include <kern/processor.h>
33 #include <mach/processor_info.h>
34 #include <i386/machine_cpu.h>
35 #include <i386/machine_routines.h>
36 #include <i386/mp_desc.h>
37
38 cpu_data_t cpu_data[NCPUS];
39 int real_ncpus = 0;
40 int wncpu = NCPUS;
41
42 /*ARGSUSED*/
43 kern_return_t
44 cpu_control(
45 int slot_num,
46 processor_info_t info,
47 unsigned int count)
48 {
49 printf("cpu_control not implemented\n");
50 return (KERN_FAILURE);
51 }
52
53 /*ARGSUSED*/
54 kern_return_t
55 cpu_info_count(
56 processor_flavor_t flavor,
57 unsigned int *count)
58 {
59 *count = 0;
60 return (KERN_FAILURE);
61 }
62
63 /*ARGSUSED*/
64 kern_return_t
65 cpu_info(
66 processor_flavor_t flavor,
67 int slot_num,
68 processor_info_t info,
69 unsigned int *count)
70 {
71 printf("cpu_info not implemented\n");
72 return (KERN_FAILURE);
73 }
74
75 void
76 cpu_sleep()
77 {
78 printf("cpu_sleep not implemented\n");
79 }
80
81 void
82 cpu_init()
83 {
84 int my_cpu = get_cpu_number();
85
86 machine_slot[my_cpu].is_cpu = TRUE;
87 machine_slot[my_cpu].running = TRUE;
88 #ifdef MACH_BSD
89 /* FIXME */
90 machine_slot[my_cpu].cpu_type = CPU_TYPE_I386;
91 machine_slot[my_cpu].cpu_subtype = CPU_SUBTYPE_PENTPRO;
92 #else
93 machine_slot[my_cpu].cpu_type = cpuid_cputype(0);
94 machine_slot[my_cpu].cpu_subtype = CPU_SUBTYPE_AT386;
95 #endif
96
97 #if NCPUS > 1
98 mp_desc_init(my_cpu);
99 #endif /* NCPUS */
100 }
101
102 kern_return_t
103 cpu_register(
104 int *target_cpu)
105 {
106 int cpu;
107
108 if (real_ncpus == 0) {
109 /*
110 * Special case for the boot processor,
111 * it has been pre-registered by cpu_init();
112 */
113 *target_cpu = 0;
114 real_ncpus++;
115 return KERN_SUCCESS;
116 }
117
118 /*
119 * TODO:
120 * - Run cpu_register() in exclusion mode
121 */
122
123 *target_cpu = -1;
124 for(cpu=0; cpu < wncpu; cpu++) {
125 if(!machine_slot[cpu].is_cpu) {
126 machine_slot[cpu].is_cpu = TRUE;
127 #ifdef MACH_BSD
128 /* FIXME */
129 machine_slot[cpu].cpu_type = CPU_TYPE_I386;
130 machine_slot[cpu].cpu_subtype = CPU_SUBTYPE_PENTPRO;
131 #else
132 machine_slot[cpu].cpu_type = cpuid_cputype(0);
133 machine_slot[cpu].cpu_subtype = CPU_SUBTYPE_AT386;
134 #endif
135 *target_cpu = cpu;
136 break;
137 }
138 }
139
140 if (*target_cpu != -1) {
141 real_ncpus++;
142 return KERN_SUCCESS;
143 } else
144 return KERN_FAILURE;
145 }
146
147 kern_return_t
148 cpu_start(
149 int cpu)
150 {
151 kern_return_t ret;
152
153 if (cpu == cpu_number()) {
154 PE_cpu_machine_init(cpu_data[cpu].cpu_id, TRUE);
155 ml_init_interrupt();
156 cpu_data[cpu].cpu_status = 1;
157 return KERN_SUCCESS;
158 } else {
159 /*
160 * Should call out through PE.
161 * But take the shortcut here.
162 */
163 ret = intel_startCPU(cpu);
164 return(ret);
165 }
166 }
167
168 void
169 cpu_machine_init(
170 void)
171 {
172 int cpu;
173
174 cpu = get_cpu_number();
175 PE_cpu_machine_init(cpu_data[cpu].cpu_id, TRUE);
176 ml_init_interrupt();
177 cpu_data[cpu].cpu_status = 1;
178 }
179