xref: /titanic_44/usr/src/uts/common/os/cpupm.c (revision 0e7515250c8395f368aa45fb9acae7c4f8f8b786)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/sunddi.h>
27 #include <sys/cpupm.h>
28 
29 /*
30  * Initialize the field that will be used for reporting
31  * the supported_frequencies_Hz cpu_info kstat.
32  */
33 void
cpupm_set_supp_freqs(cpu_t * cp,int * speeds,uint_t nspeeds)34 cpupm_set_supp_freqs(cpu_t *cp, int *speeds, uint_t nspeeds)
35 {
36 	char		*supp_freqs = NULL;
37 	char		*sfptr;
38 	uint64_t	*hzspeeds;
39 	int		i;
40 	int		j;
41 #define	UINT64_MAX_STRING (sizeof ("18446744073709551615"))
42 
43 	if (speeds == NULL) {
44 		cpu_set_supp_freqs(cp, supp_freqs);
45 		return;
46 	}
47 
48 	hzspeeds = kmem_zalloc(nspeeds * sizeof (uint64_t), KM_SLEEP);
49 	for (i = nspeeds - 1, j = 0; i >= 0; i--, j++) {
50 		hzspeeds[i] = CPUPM_SPEED_HZ(cp->cpu_type_info.pi_clock,
51 		    speeds[j]);
52 	}
53 
54 	supp_freqs = kmem_zalloc((UINT64_MAX_STRING * nspeeds), KM_SLEEP);
55 	sfptr = supp_freqs;
56 	for (i = 0; i < nspeeds; i++) {
57 		if (i == nspeeds - 1) {
58 			(void) sprintf(sfptr, "%"PRIu64, hzspeeds[i]);
59 		} else {
60 			(void) sprintf(sfptr, "%"PRIu64":", hzspeeds[i]);
61 			sfptr = supp_freqs + strlen(supp_freqs);
62 		}
63 	}
64 	cpu_set_supp_freqs(cp, supp_freqs);
65 	kmem_free(supp_freqs, (UINT64_MAX_STRING * nspeeds));
66 	kmem_free(hzspeeds, nspeeds * sizeof (uint64_t));
67 }
68