1*0e751525SEric Saxe /*
2*0e751525SEric Saxe * CDDL HEADER START
3*0e751525SEric Saxe *
4*0e751525SEric Saxe * The contents of this file are subject to the terms of the
5*0e751525SEric Saxe * Common Development and Distribution License (the "License").
6*0e751525SEric Saxe * You may not use this file except in compliance with the License.
7*0e751525SEric Saxe *
8*0e751525SEric Saxe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*0e751525SEric Saxe * or http://www.opensolaris.org/os/licensing.
10*0e751525SEric Saxe * See the License for the specific language governing permissions
11*0e751525SEric Saxe * and limitations under the License.
12*0e751525SEric Saxe *
13*0e751525SEric Saxe * When distributing Covered Code, include this CDDL HEADER in each
14*0e751525SEric Saxe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*0e751525SEric Saxe * If applicable, add the following below this CDDL HEADER, with the
16*0e751525SEric Saxe * fields enclosed by brackets "[]" replaced with your own identifying
17*0e751525SEric Saxe * information: Portions Copyright [yyyy] [name of copyright owner]
18*0e751525SEric Saxe *
19*0e751525SEric Saxe * CDDL HEADER END
20*0e751525SEric Saxe */
21*0e751525SEric Saxe /*
22*0e751525SEric Saxe * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23*0e751525SEric Saxe * Use is subject to license terms.
24*0e751525SEric Saxe */
25*0e751525SEric Saxe
26*0e751525SEric Saxe #include <sys/sunddi.h>
27*0e751525SEric Saxe #include <sys/cpupm.h>
28*0e751525SEric Saxe
29*0e751525SEric Saxe /*
30*0e751525SEric Saxe * Initialize the field that will be used for reporting
31*0e751525SEric Saxe * the supported_frequencies_Hz cpu_info kstat.
32*0e751525SEric Saxe */
33*0e751525SEric Saxe void
cpupm_set_supp_freqs(cpu_t * cp,int * speeds,uint_t nspeeds)34*0e751525SEric Saxe cpupm_set_supp_freqs(cpu_t *cp, int *speeds, uint_t nspeeds)
35*0e751525SEric Saxe {
36*0e751525SEric Saxe char *supp_freqs = NULL;
37*0e751525SEric Saxe char *sfptr;
38*0e751525SEric Saxe uint64_t *hzspeeds;
39*0e751525SEric Saxe int i;
40*0e751525SEric Saxe int j;
41*0e751525SEric Saxe #define UINT64_MAX_STRING (sizeof ("18446744073709551615"))
42*0e751525SEric Saxe
43*0e751525SEric Saxe if (speeds == NULL) {
44*0e751525SEric Saxe cpu_set_supp_freqs(cp, supp_freqs);
45*0e751525SEric Saxe return;
46*0e751525SEric Saxe }
47*0e751525SEric Saxe
48*0e751525SEric Saxe hzspeeds = kmem_zalloc(nspeeds * sizeof (uint64_t), KM_SLEEP);
49*0e751525SEric Saxe for (i = nspeeds - 1, j = 0; i >= 0; i--, j++) {
50*0e751525SEric Saxe hzspeeds[i] = CPUPM_SPEED_HZ(cp->cpu_type_info.pi_clock,
51*0e751525SEric Saxe speeds[j]);
52*0e751525SEric Saxe }
53*0e751525SEric Saxe
54*0e751525SEric Saxe supp_freqs = kmem_zalloc((UINT64_MAX_STRING * nspeeds), KM_SLEEP);
55*0e751525SEric Saxe sfptr = supp_freqs;
56*0e751525SEric Saxe for (i = 0; i < nspeeds; i++) {
57*0e751525SEric Saxe if (i == nspeeds - 1) {
58*0e751525SEric Saxe (void) sprintf(sfptr, "%"PRIu64, hzspeeds[i]);
59*0e751525SEric Saxe } else {
60*0e751525SEric Saxe (void) sprintf(sfptr, "%"PRIu64":", hzspeeds[i]);
61*0e751525SEric Saxe sfptr = supp_freqs + strlen(supp_freqs);
62*0e751525SEric Saxe }
63*0e751525SEric Saxe }
64*0e751525SEric Saxe cpu_set_supp_freqs(cp, supp_freqs);
65*0e751525SEric Saxe kmem_free(supp_freqs, (UINT64_MAX_STRING * nspeeds));
66*0e751525SEric Saxe kmem_free(hzspeeds, nspeeds * sizeof (uint64_t));
67*0e751525SEric Saxe }
68