4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/machsystm.h>
27 #include <sys/cpu_module.h>
28 #include <sys/dtrace.h>
29 #include <sys/cpu_sgnblk_defs.h>
32 * Useful for disabling MP bring-up for an MP capable kernel
33 * (a kernel that was built with MP defined)
35 int use_mp
= 1; /* set to come up mp */
38 * Init CPU info - get CPU type info for processor_info system call.
41 init_cpu_info(struct cpu
*cp
)
43 processor_info_t
*pi
= &cp
->cpu_type_info
;
44 int cpuid
= cp
->cpu_id
;
45 struct cpu_node
*cpunode
= &cpunodes
[cpuid
];
47 cp
->cpu_fpowner
= NULL
; /* not used for V9 */
50 * Get clock-frequency property from cpunodes[] for the CPU.
52 pi
->pi_clock
= (cpunode
->clock_freq
+ 500000) / 1000000;
55 * Current frequency in Hz.
57 cp
->cpu_curr_clock
= cpunode
->clock_freq
;
60 * Supported frequencies.
62 cpu_set_supp_freqs(cp
, NULL
);
64 (void) strcpy(pi
->pi_processor_type
, "sparcv9");
65 (void) strcpy(pi
->pi_fputypes
, "sparcv9");
68 * StarFire requires the signature block stuff setup here
71 if (cpuid
== cpu0
.cpu_id
) {
73 * cpu0 starts out running. Other cpus are
74 * still in OBP land and we will leave them
77 CPU_SIGNATURE(OS_SIG
, SIGST_RUN
, SIGSUBST_NULL
, cpuid
);
85 * Routine used to cleanup a CPU that has been powered off. This will
86 * destroy all per-cpu information related to this cpu.
89 mp_cpu_unconfigure(int cpuid
)
93 extern int cleanup_cpu_common(int);
95 ASSERT(MUTEX_HELD(&cpu_lock
));
97 retval
= cleanup_cpu_common(cpuid
);
104 struct mp_find_cpu_arg
{
105 int cpuid
; /* set by mp_cpu_configure() */
106 dev_info_t
*dip
; /* set by mp_find_cpu() */
110 mp_find_cpu(dev_info_t
*dip
, void *arg
)
112 extern int get_portid_ddi(dev_info_t
*, dev_info_t
**);
113 struct mp_find_cpu_arg
*target
= (struct mp_find_cpu_arg
*)arg
;
115 int rv
= DDI_WALK_CONTINUE
;
118 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, dip
, DDI_PROP_DONTPASS
,
119 "device_type", &type
))
120 return (DDI_WALK_CONTINUE
);
122 if (strcmp(type
, "cpu") != 0)
125 cpuid
= ddi_prop_get_int(DDI_DEV_T_ANY
, dip
,
126 DDI_PROP_DONTPASS
, "cpuid", -1);
129 cpuid
= get_portid_ddi(dip
, NULL
);
130 if (cpuid
!= target
->cpuid
)
134 rv
= DDI_WALK_TERMINATE
;
143 * Routine used to setup a newly inserted CPU in preparation for starting
147 mp_cpu_configure(int cpuid
)
149 extern void fill_cpu_ddi(dev_info_t
*);
150 extern int setup_cpu_common(int);
151 struct mp_find_cpu_arg target
;
153 ASSERT(MUTEX_HELD(&cpu_lock
));
156 target
.cpuid
= cpuid
;
157 ddi_walk_devs(ddi_root_node(), mp_find_cpu
, &target
);
159 if (target
.dip
== NULL
)
163 * Note: uses cpu_lock to protect cpunodes and ncpunodes
164 * which will be modified inside of fill_cpu_ddi().
166 fill_cpu_ddi(target
.dip
);
169 * sun4v cpu setup may fail. sun4u assumes cpu setup to
170 * be always successful, so the return value is ignored.
172 (void) setup_cpu_common(cpuid
);
178 populate_idstr(struct cpu
*cp
)
180 char buf
[CPU_IDSTRLEN
];
181 struct cpu_node
*cpunode
;
182 processor_info_t
*pi
;
184 cpunode
= &cpunodes
[cp
->cpu_id
];
185 pi
= &cp
->cpu_type_info
;
186 (void) snprintf(buf
, sizeof (buf
),
187 "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)",
188 cpunode
->name
, cpunode
->portid
, cpunode
->implementation
,
189 cpunode
->version
, pi
->pi_clock
);
190 cp
->cpu_idstr
= kmem_alloc(strlen(buf
) + 1, KM_SLEEP
);
191 (void) strcpy(cp
->cpu_idstr
, buf
);
193 cp
->cpu_brandstr
= kmem_alloc(strlen(cpunode
->name
) + 1, KM_SLEEP
);
194 (void) strcpy(cp
->cpu_brandstr
, cpunode
->name
);
196 cmn_err(CE_CONT
, "?cpu%d: %s\n", cp
->cpu_id
, cp
->cpu_idstr
);