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