Merge commit 'ea01a15a654b9e1c7b37d958f4d1911882ed7781'
[unleashed.git] / kernel / os / cpupm.c
blob1e1aa97bf5d0b7cc6a8ccef323a99f9b22efbbb0
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/sunddi.h>
27 #include <sys/cpupm.h>
30 * Initialize the field that will be used for reporting
31 * the supported_frequencies_Hz cpu_info kstat.
33 void
34 cpupm_set_supp_freqs(cpu_t *cp, int *speeds, uint_t nspeeds)
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"))
43 if (speeds == NULL) {
44 cpu_set_supp_freqs(cp, supp_freqs);
45 return;
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]);
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);
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));