1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/machsystm.h> 29 #include <sys/cpu_module.h> 30 #include <sys/dtrace.h> 31 #include <sys/cpu_sgnblk_defs.h> 32 33 /* 34 * Useful for disabling MP bring-up for an MP capable kernel 35 * (a kernel that was built with MP defined) 36 */ 37 int use_mp = 1; /* set to come up mp */ 38 39 /* 40 * Init CPU info - get CPU type info for processor_info system call. 41 */ 42 void 43 init_cpu_info(struct cpu *cp) 44 { 45 processor_info_t *pi = &cp->cpu_type_info; 46 int cpuid = cp->cpu_id; 47 struct cpu_node *cpunode = &cpunodes[cpuid]; 48 char buf[CPU_IDSTRLEN]; 49 50 cp->cpu_fpowner = NULL; /* not used for V9 */ 51 52 /* 53 * Get clock-frequency property from cpunodes[] for the CPU. 54 */ 55 pi->pi_clock = (cpunode->clock_freq + 500000) / 1000000; 56 57 /* 58 * Current frequency in Hz. 59 */ 60 cp->cpu_curr_clock = cpunode->clock_freq; 61 62 /* 63 * Supported frequencies. 64 */ 65 cpu_set_supp_freqs(cp, NULL); 66 67 (void) strcpy(pi->pi_processor_type, "sparcv9"); 68 (void) strcpy(pi->pi_fputypes, "sparcv9"); 69 70 (void) snprintf(buf, sizeof (buf), 71 "%s (portid %d impl 0x%x ver 0x%x clock %d MHz)", 72 cpunode->name, cpunode->portid, 73 cpunode->implementation, cpunode->version, pi->pi_clock); 74 75 cp->cpu_idstr = kmem_alloc(strlen(buf) + 1, KM_SLEEP); 76 (void) strcpy(cp->cpu_idstr, buf); 77 78 cmn_err(CE_CONT, "?cpu%d: %s\n", cpuid, cp->cpu_idstr); 79 80 cp->cpu_brandstr = kmem_alloc(strlen(cpunode->name) + 1, KM_SLEEP); 81 (void) strcpy(cp->cpu_brandstr, cpunode->name); 82 83 /* 84 * StarFire requires the signature block stuff setup here 85 */ 86 CPU_SGN_MAPIN(cpuid); 87 if (cpuid == cpu0.cpu_id) { 88 /* 89 * cpu0 starts out running. Other cpus are 90 * still in OBP land and we will leave them 91 * alone for now. 92 */ 93 CPU_SIGNATURE(OS_SIG, SIGST_RUN, SIGSUBST_NULL, cpuid); 94 #ifdef lint 95 cpuid = cpuid; 96 #endif /* lint */ 97 } 98 } 99 100 /* 101 * Routine used to cleanup a CPU that has been powered off. This will 102 * destroy all per-cpu information related to this cpu. 103 */ 104 int 105 mp_cpu_unconfigure(int cpuid) 106 { 107 int retval; 108 void empty_cpu(int); 109 extern int cleanup_cpu_common(int); 110 111 ASSERT(MUTEX_HELD(&cpu_lock)); 112 113 retval = cleanup_cpu_common(cpuid); 114 115 empty_cpu(cpuid); 116 117 return (retval); 118 } 119 120 struct mp_find_cpu_arg { 121 int cpuid; /* set by mp_cpu_configure() */ 122 dev_info_t *dip; /* set by mp_find_cpu() */ 123 }; 124 125 int 126 mp_find_cpu(dev_info_t *dip, void *arg) 127 { 128 extern int get_portid_ddi(dev_info_t *, dev_info_t **); 129 struct mp_find_cpu_arg *target = (struct mp_find_cpu_arg *)arg; 130 char *type; 131 int rv = DDI_WALK_CONTINUE; 132 int cpuid; 133 134 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 135 "device_type", &type)) 136 return (DDI_WALK_CONTINUE); 137 138 if (strcmp(type, "cpu") != 0) 139 goto out; 140 141 cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, 142 DDI_PROP_DONTPASS, "cpuid", -1); 143 144 if (cpuid == -1) 145 cpuid = get_portid_ddi(dip, NULL); 146 if (cpuid != target->cpuid) 147 goto out; 148 149 /* Found it */ 150 rv = DDI_WALK_TERMINATE; 151 target->dip = dip; 152 153 out: 154 ddi_prop_free(type); 155 return (rv); 156 } 157 158 /* 159 * Routine used to setup a newly inserted CPU in preparation for starting 160 * it running code. 161 */ 162 int 163 mp_cpu_configure(int cpuid) 164 { 165 extern void fill_cpu_ddi(dev_info_t *); 166 extern int setup_cpu_common(int); 167 struct mp_find_cpu_arg target; 168 169 ASSERT(MUTEX_HELD(&cpu_lock)); 170 171 target.dip = NULL; 172 target.cpuid = cpuid; 173 ddi_walk_devs(ddi_root_node(), mp_find_cpu, &target); 174 175 if (target.dip == NULL) 176 return (ENODEV); 177 178 /* 179 * Note: uses cpu_lock to protect cpunodes and ncpunodes 180 * which will be modified inside of fill_cpu_ddi(). 181 */ 182 fill_cpu_ddi(target.dip); 183 184 /* 185 * sun4v cpu setup may fail. sun4u assumes cpu setup to 186 * be always successful, so the return value is ignored. 187 */ 188 (void) setup_cpu_common(cpuid); 189 190 return (0); 191 } 192