acpi_cpu_md.c revision 1.26 1 /* $NetBSD: acpi_cpu_md.c,v 1.26 2010/08/21 07:18:34 jruoho Exp $ */
2
3 /*-
4 * Copyright (c) 2010 Jukka Ruohonen <jruohonen (at) iki.fi>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.26 2010/08/21 07:18:34 jruoho Exp $");
31
32 #include <sys/param.h>
33 #include <sys/bus.h>
34 #include <sys/kcore.h>
35 #include <sys/sysctl.h>
36 #include <sys/xcall.h>
37
38 #include <x86/cpu.h>
39 #include <x86/cpufunc.h>
40 #include <x86/cputypes.h>
41 #include <x86/cpuvar.h>
42 #include <x86/cpu_msr.h>
43 #include <x86/machdep.h>
44
45 #include <dev/acpi/acpica.h>
46 #include <dev/acpi/acpi_cpu.h>
47
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcidevs.h>
50
51 #define CPUID_INTEL_TSC __BIT(8)
52
53 #define MSR_0FH_CONTROL 0xc0010041 /* Family 0Fh (and K7). */
54 #define MSR_0FH_STATUS 0xc0010042
55
56 #define MSR_10H_LIMIT 0xc0010061 /* Families 10h and 11h. */
57 #define MSR_10H_CONTROL 0xc0010062
58 #define MSR_10H_STATUS 0xc0010063
59 #define MSR_10H_CONFIG 0xc0010064
60
61 static char native_idle_text[16];
62 void (*native_idle)(void) = NULL;
63
64 static int acpicpu_md_quirks_piix4(struct pci_attach_args *);
65 static void acpicpu_md_pstate_status(void *, void *);
66 static void acpicpu_md_tstate_status(void *, void *);
67 static int acpicpu_md_pstate_sysctl_init(void);
68 static int acpicpu_md_pstate_sysctl_get(SYSCTLFN_PROTO);
69 static int acpicpu_md_pstate_sysctl_set(SYSCTLFN_PROTO);
70 static int acpicpu_md_pstate_sysctl_all(SYSCTLFN_PROTO);
71
72 extern uint32_t cpus_running;
73 extern struct acpicpu_softc **acpicpu_sc;
74 static struct sysctllog *acpicpu_log = NULL;
75
76 uint32_t
77 acpicpu_md_cap(void)
78 {
79 struct cpu_info *ci = curcpu();
80 uint32_t val = 0;
81
82 if (cpu_vendor != CPUVENDOR_IDT &&
83 cpu_vendor != CPUVENDOR_INTEL)
84 return val;
85
86 /*
87 * Basic SMP C-states (required for _CST).
88 */
89 val |= ACPICPU_PDC_C_C1PT | ACPICPU_PDC_C_C2C3;
90
91 /*
92 * If MONITOR/MWAIT is available, announce
93 * support for native instructions in all C-states.
94 */
95 if ((ci->ci_feat_val[1] & CPUID2_MONITOR) != 0)
96 val |= ACPICPU_PDC_C_C1_FFH | ACPICPU_PDC_C_C2C3_FFH;
97
98 /*
99 * Set native P- and T-states, if available.
100 */
101 if ((ci->ci_feat_val[1] & CPUID2_EST) != 0)
102 val |= ACPICPU_PDC_P_FFH;
103
104 if ((ci->ci_feat_val[0] & CPUID_ACPI) != 0)
105 val |= ACPICPU_PDC_T_FFH;
106
107 return val;
108 }
109
110 uint32_t
111 acpicpu_md_quirks(void)
112 {
113 struct cpu_info *ci = curcpu();
114 struct pci_attach_args pa;
115 uint32_t family, val = 0;
116 uint32_t regs[4];
117
118 if (acpicpu_md_cpus_running() == 1)
119 val |= ACPICPU_FLAG_C_BM;
120
121 if ((ci->ci_feat_val[1] & CPUID2_MONITOR) != 0)
122 val |= ACPICPU_FLAG_C_FFH;
123
124 val |= ACPICPU_FLAG_C_APIC | ACPICPU_FLAG_C_TSC;
125
126 switch (cpu_vendor) {
127
128 case CPUVENDOR_IDT:
129
130 if ((ci->ci_feat_val[1] & CPUID2_EST) != 0)
131 val |= ACPICPU_FLAG_P_FFH;
132
133 if ((ci->ci_feat_val[0] & CPUID_ACPI) != 0)
134 val |= ACPICPU_FLAG_T_FFH;
135
136 break;
137
138 case CPUVENDOR_INTEL:
139
140 val |= ACPICPU_FLAG_C_BM | ACPICPU_FLAG_C_ARB;
141
142 if ((ci->ci_feat_val[1] & CPUID2_EST) != 0)
143 val |= ACPICPU_FLAG_P_FFH;
144
145 if ((ci->ci_feat_val[0] & CPUID_ACPI) != 0)
146 val |= ACPICPU_FLAG_T_FFH;
147
148 /*
149 * Check whether MSR_APERF, MSR_MPERF, and Turbo
150 * Boost are available. Also see if we might have
151 * an invariant local APIC timer ("ARAT").
152 */
153 if (cpuid_level >= 0x06) {
154
155 x86_cpuid(0x06, regs);
156
157 if ((regs[2] & __BIT(0)) != 0) /* ECX.06[0] */
158 val |= ACPICPU_FLAG_P_HW;
159
160 if ((regs[0] & __BIT(1)) != 0) /* EAX.06[1] */
161 val |= ACPICPU_FLAG_P_TURBO;
162
163 if ((regs[0] & __BIT(2)) != 0) /* EAX.06[2] */
164 val &= ~ACPICPU_FLAG_C_APIC;
165 }
166
167 /*
168 * Detect whether TSC is invariant. If it is not,
169 * we keep the flag to note that TSC will not run
170 * at constant rate. Depending on the CPU, this may
171 * affect P- and T-state changes, but especially
172 * relevant are C-states; with variant TSC, states
173 * larger than C1 may completely stop the counter.
174 */
175 x86_cpuid(0x80000000, regs);
176
177 if (regs[0] >= 0x80000007) {
178
179 x86_cpuid(0x80000007, regs);
180
181 if ((regs[3] & CPUID_INTEL_TSC) != 0)
182 val &= ~ACPICPU_FLAG_C_TSC;
183 }
184
185 break;
186
187 case CPUVENDOR_AMD:
188
189 family = CPUID2FAMILY(ci->ci_signature);
190
191 if (family == 0xf)
192 family += CPUID2EXTFAMILY(ci->ci_signature);
193
194 switch (family) {
195
196 case 0x0f:
197 case 0x10:
198 case 0x11:
199
200 x86_cpuid(0x80000007, regs);
201
202 if ((regs[3] & CPUID_APM_TSC) != 0)
203 val &= ~ACPICPU_FLAG_C_TSC;
204
205 if ((regs[3] & CPUID_APM_HWP) != 0)
206 val |= ACPICPU_FLAG_P_FFH;
207
208 if ((regs[3] & CPUID_APM_CPB) != 0)
209 val |= ACPICPU_FLAG_P_TURBO;
210 }
211
212 break;
213 }
214
215 /*
216 * There are several erratums for PIIX4.
217 */
218 if (pci_find_device(&pa, acpicpu_md_quirks_piix4) != 0)
219 val |= ACPICPU_FLAG_PIIX4;
220
221 return val;
222 }
223
224 static int
225 acpicpu_md_quirks_piix4(struct pci_attach_args *pa)
226 {
227
228 /*
229 * XXX: The pci_find_device(9) function only
230 * deals with attached devices. Change this
231 * to use something like pci_device_foreach().
232 */
233 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
234 return 0;
235
236 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82371AB_ISA ||
237 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_82440MX_PMC)
238 return 1;
239
240 return 0;
241 }
242
243 uint32_t
244 acpicpu_md_cpus_running(void)
245 {
246
247 return popcount32(cpus_running);
248 }
249
250 int
251 acpicpu_md_idle_start(void)
252 {
253 const size_t size = sizeof(native_idle_text);
254
255 x86_disable_intr();
256 x86_cpu_idle_get(&native_idle, native_idle_text, size);
257 x86_cpu_idle_set(acpicpu_cstate_idle, "acpi");
258 x86_enable_intr();
259
260 return 0;
261 }
262
263 int
264 acpicpu_md_idle_stop(void)
265 {
266 uint64_t xc;
267
268 x86_disable_intr();
269 x86_cpu_idle_set(native_idle, native_idle_text);
270 x86_enable_intr();
271
272 /*
273 * Run a cross-call to ensure that all CPUs are
274 * out from the ACPI idle-loop before detachment.
275 */
276 xc = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL);
277 xc_wait(xc);
278
279 return 0;
280 }
281
282 /*
283 * The MD idle loop. Called with interrupts disabled.
284 */
285 void
286 acpicpu_md_idle_enter(int method, int state)
287 {
288 struct cpu_info *ci = curcpu();
289
290 switch (method) {
291
292 case ACPICPU_C_STATE_FFH:
293
294 x86_enable_intr();
295 x86_monitor(&ci->ci_want_resched, 0, 0);
296
297 if (__predict_false(ci->ci_want_resched) != 0)
298 return;
299
300 x86_mwait((state - 1) << 4, 0);
301 break;
302
303 case ACPICPU_C_STATE_HALT:
304
305 if (__predict_false(ci->ci_want_resched) != 0) {
306 x86_enable_intr();
307 return;
308 }
309
310 x86_stihlt();
311 break;
312 }
313 }
314
315 int
316 acpicpu_md_pstate_start(void)
317 {
318 const uint64_t est = __BIT(16);
319 uint64_t val;
320
321 switch (cpu_vendor) {
322
323 case CPUVENDOR_IDT:
324 case CPUVENDOR_INTEL:
325
326 val = rdmsr(MSR_MISC_ENABLE);
327
328 if ((val & est) == 0) {
329
330 val |= est;
331
332 wrmsr(MSR_MISC_ENABLE, val);
333 val = rdmsr(MSR_MISC_ENABLE);
334
335 if ((val & est) == 0)
336 return ENOTTY;
337 }
338 }
339
340 return acpicpu_md_pstate_sysctl_init();
341 }
342
343 int
344 acpicpu_md_pstate_stop(void)
345 {
346
347 if (acpicpu_log != NULL)
348 sysctl_teardown(&acpicpu_log);
349
350 return 0;
351 }
352
353 int
354 acpicpu_md_pstate_pss(struct acpicpu_softc *sc)
355 {
356 struct acpicpu_pstate *ps, msr;
357 struct cpu_info *ci = curcpu();
358 uint32_t family, i = 0;
359
360 (void)memset(&msr, 0, sizeof(struct acpicpu_pstate));
361
362 switch (cpu_vendor) {
363
364 case CPUVENDOR_IDT:
365 case CPUVENDOR_INTEL:
366 msr.ps_control_addr = MSR_PERF_CTL;
367 msr.ps_control_mask = __BITS(0, 15);
368
369 msr.ps_status_addr = MSR_PERF_STATUS;
370 msr.ps_status_mask = __BITS(0, 15);
371 break;
372
373 case CPUVENDOR_AMD:
374
375 family = CPUID2FAMILY(ci->ci_signature);
376
377 if (family == 0xf)
378 family += CPUID2EXTFAMILY(ci->ci_signature);
379
380 switch (family) {
381
382 case 0x10:
383 case 0x11:
384 msr.ps_control_addr = MSR_10H_CONTROL;
385 msr.ps_control_mask = __BITS(0, 2);
386
387 msr.ps_status_addr = MSR_10H_STATUS;
388 msr.ps_status_mask = __BITS(0, 2);
389 break;
390
391 default:
392
393 if ((sc->sc_flags & ACPICPU_FLAG_P_XPSS) == 0)
394 return EOPNOTSUPP;
395 }
396
397 break;
398
399 default:
400 return ENODEV;
401 }
402
403 /*
404 * Fill the P-state structures with MSR addresses that are
405 * known to be correct. But only do this when the values
406 * reported by BIOS are absent. If a vendor uses XPSS, we
407 * do not necessary need to do anything to support new CPUs.
408 */
409 while (i < sc->sc_pstate_count) {
410
411 ps = &sc->sc_pstate[i];
412
413 if (ps->ps_status_addr == 0)
414 ps->ps_status_addr = msr.ps_status_addr;
415
416 if (ps->ps_status_mask == 0)
417 ps->ps_status_mask = msr.ps_status_mask;
418
419 if (ps->ps_control_addr == 0)
420 ps->ps_control_addr = msr.ps_control_addr;
421
422 if (ps->ps_control_mask == 0)
423 ps->ps_control_mask = msr.ps_control_mask;
424
425 i++;
426 }
427
428 /*
429 * When the state is P0 and Turbo Boost has been
430 * detected, we need to skip the status check as
431 * BIOS may not report right comparison values for
432 * the IA32_PERF_STATUS register. Note that this
433 * issue is specific to Intel. For discussion, see:
434 *
435 * Intel Corporation: Intel Turbo Boost Technology
436 * in Intel Core(tm) Microarchitectures (Nehalem)
437 * Based Processors. White Paper, November 2008.
438 */
439 if (cpu_vendor != CPUVENDOR_INTEL)
440 return 0;
441
442 if ((sc->sc_flags & ACPICPU_FLAG_P_TURBO) == 0)
443 return 0;
444
445 if (sc->sc_pstate[1].ps_freq + 1 == sc->sc_pstate[0].ps_freq)
446 sc->sc_pstate[0].ps_flags |= ACPICPU_FLAG_P_TURBO;
447
448 return 0;
449 }
450
451 int
452 acpicpu_md_pstate_get(struct acpicpu_softc *sc, uint32_t *freq)
453 {
454 struct acpicpu_pstate *ps = NULL;
455 uint64_t val;
456 uint32_t i;
457
458 for (i = 0; i < sc->sc_pstate_count; i++) {
459
460 ps = &sc->sc_pstate[i];
461
462 if (ps->ps_freq != 0)
463 break;
464 }
465
466 if (__predict_false(ps == NULL))
467 return ENODEV;
468
469 if (ps->ps_status_addr == 0)
470 return EINVAL;
471
472 val = rdmsr(ps->ps_status_addr);
473
474 if (ps->ps_status_mask != 0)
475 val = val & ps->ps_status_mask;
476
477 for (i = 0; i < sc->sc_pstate_count; i++) {
478
479 ps = &sc->sc_pstate[i];
480
481 if (ps->ps_freq == 0)
482 continue;
483
484 if (val == ps->ps_status) {
485 *freq = ps->ps_freq;
486 return 0;
487 }
488 }
489
490 return EIO;
491 }
492
493 int
494 acpicpu_md_pstate_set(struct acpicpu_pstate *ps)
495 {
496 struct msr_rw_info msr;
497 uint64_t xc;
498 int rv = 0;
499
500 msr.msr_read = false;
501 msr.msr_type = ps->ps_control_addr;
502 msr.msr_value = ps->ps_control;
503
504 if (__predict_true(ps->ps_control_mask != 0)) {
505 msr.msr_mask = ps->ps_control_mask;
506 msr.msr_read = true;
507 }
508
509 xc = xc_broadcast(0, (xcfunc_t)x86_msr_xcall, &msr, NULL);
510 xc_wait(xc);
511
512 if (__predict_false(ps->ps_status_addr == 0))
513 return 0;
514
515 if ((ps->ps_flags & ACPICPU_FLAG_P_TURBO) != 0)
516 return 0;
517
518 xc = xc_broadcast(0, (xcfunc_t)acpicpu_md_pstate_status, ps, &rv);
519 xc_wait(xc);
520
521 return rv;
522 }
523
524 static void
525 acpicpu_md_pstate_status(void *arg1, void *arg2)
526 {
527 struct acpicpu_pstate *ps = arg1;
528 uint64_t val;
529 int i;
530
531 for (i = val = 0; i < ACPICPU_P_STATE_RETRY; i++) {
532
533 val = rdmsr(ps->ps_status_addr);
534
535 if (__predict_true(ps->ps_status_mask != 0))
536 val = val & ps->ps_status_mask;
537
538 if (val == ps->ps_status)
539 return;
540
541 DELAY(ps->ps_latency);
542 }
543
544 *(uintptr_t *)arg2 = EAGAIN;
545 }
546
547 int
548 acpicpu_md_tstate_get(struct acpicpu_softc *sc, uint32_t *percent)
549 {
550 struct acpicpu_tstate *ts;
551 uint64_t val;
552 uint32_t i;
553
554 val = rdmsr(MSR_THERM_CONTROL);
555
556 for (i = 0; i < sc->sc_tstate_count; i++) {
557
558 ts = &sc->sc_tstate[i];
559
560 if (ts->ts_percent == 0)
561 continue;
562
563 if (val == ts->ts_control || val == ts->ts_status) {
564 *percent = ts->ts_percent;
565 return 0;
566 }
567 }
568
569 return EIO;
570 }
571
572 int
573 acpicpu_md_tstate_set(struct acpicpu_tstate *ts)
574 {
575 struct msr_rw_info msr;
576 uint64_t xc;
577 int rv = 0;
578
579 msr.msr_read = true;
580 msr.msr_type = MSR_THERM_CONTROL;
581 msr.msr_value = ts->ts_control;
582 msr.msr_mask = __BITS(1, 4);
583
584 xc = xc_broadcast(0, (xcfunc_t)x86_msr_xcall, &msr, NULL);
585 xc_wait(xc);
586
587 if (ts->ts_status == 0)
588 return 0;
589
590 xc = xc_broadcast(0, (xcfunc_t)acpicpu_md_tstate_status, ts, &rv);
591 xc_wait(xc);
592
593 return rv;
594 }
595
596 static void
597 acpicpu_md_tstate_status(void *arg1, void *arg2)
598 {
599 struct acpicpu_tstate *ts = arg1;
600 uint64_t val;
601 int i;
602
603 for (i = val = 0; i < ACPICPU_T_STATE_RETRY; i++) {
604
605 val = rdmsr(MSR_THERM_CONTROL);
606
607 if (val == ts->ts_status)
608 return;
609
610 DELAY(ts->ts_latency);
611 }
612
613 *(uintptr_t *)arg2 = EAGAIN;
614 }
615
616 /*
617 * A kludge for backwards compatibility.
618 */
619 static int
620 acpicpu_md_pstate_sysctl_init(void)
621 {
622 const struct sysctlnode *fnode, *mnode, *rnode;
623 const char *str;
624 int rv;
625
626 switch (cpu_vendor) {
627
628 case CPUVENDOR_IDT:
629 case CPUVENDOR_INTEL:
630 str = "est";
631 break;
632
633 case CPUVENDOR_AMD:
634 str = "powernow";
635 break;
636
637 default:
638 return ENODEV;
639 }
640
641
642 rv = sysctl_createv(&acpicpu_log, 0, NULL, &rnode,
643 CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
644 NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
645
646 if (rv != 0)
647 goto fail;
648
649 rv = sysctl_createv(&acpicpu_log, 0, &rnode, &mnode,
650 0, CTLTYPE_NODE, str, NULL,
651 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
652
653 if (rv != 0)
654 goto fail;
655
656 rv = sysctl_createv(&acpicpu_log, 0, &mnode, &fnode,
657 0, CTLTYPE_NODE, "frequency", NULL,
658 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
659
660 if (rv != 0)
661 goto fail;
662
663 rv = sysctl_createv(&acpicpu_log, 0, &fnode, &rnode,
664 CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
665 acpicpu_md_pstate_sysctl_set, 0, NULL, 0, CTL_CREATE, CTL_EOL);
666
667 if (rv != 0)
668 goto fail;
669
670 rv = sysctl_createv(&acpicpu_log, 0, &fnode, &rnode,
671 CTLFLAG_READONLY, CTLTYPE_INT, "current", NULL,
672 acpicpu_md_pstate_sysctl_get, 0, NULL, 0, CTL_CREATE, CTL_EOL);
673
674 if (rv != 0)
675 goto fail;
676
677 rv = sysctl_createv(&acpicpu_log, 0, &fnode, &rnode,
678 CTLFLAG_READONLY, CTLTYPE_STRING, "available", NULL,
679 acpicpu_md_pstate_sysctl_all, 0, NULL, 0, CTL_CREATE, CTL_EOL);
680
681 if (rv != 0)
682 goto fail;
683
684 return 0;
685
686 fail:
687 if (acpicpu_log != NULL) {
688 sysctl_teardown(&acpicpu_log);
689 acpicpu_log = NULL;
690 }
691
692 return rv;
693 }
694
695 static int
696 acpicpu_md_pstate_sysctl_get(SYSCTLFN_ARGS)
697 {
698 struct cpu_info *ci = curcpu();
699 struct acpicpu_softc *sc;
700 struct sysctlnode node;
701 uint32_t freq;
702 int err;
703
704 sc = acpicpu_sc[ci->ci_acpiid];
705
706 if (sc == NULL)
707 return ENXIO;
708
709 err = acpicpu_pstate_get(sc, &freq);
710
711 if (err != 0)
712 return err;
713
714 node = *rnode;
715 node.sysctl_data = &freq;
716
717 err = sysctl_lookup(SYSCTLFN_CALL(&node));
718
719 if (err != 0 || newp == NULL)
720 return err;
721
722 return 0;
723 }
724
725 static int
726 acpicpu_md_pstate_sysctl_set(SYSCTLFN_ARGS)
727 {
728 struct cpu_info *ci = curcpu();
729 struct acpicpu_softc *sc;
730 struct sysctlnode node;
731 uint32_t freq;
732 int err;
733
734 sc = acpicpu_sc[ci->ci_acpiid];
735
736 if (sc == NULL)
737 return ENXIO;
738
739 err = acpicpu_pstate_get(sc, &freq);
740
741 if (err != 0)
742 return err;
743
744 node = *rnode;
745 node.sysctl_data = &freq;
746
747 err = sysctl_lookup(SYSCTLFN_CALL(&node));
748
749 if (err != 0 || newp == NULL)
750 return err;
751
752 err = acpicpu_pstate_set(sc, freq);
753
754 if (err != 0)
755 return err;
756
757 return 0;
758 }
759
760 static int
761 acpicpu_md_pstate_sysctl_all(SYSCTLFN_ARGS)
762 {
763 struct cpu_info *ci = curcpu();
764 struct acpicpu_softc *sc;
765 struct sysctlnode node;
766 char buf[1024];
767 size_t len;
768 uint32_t i;
769 int err;
770
771 sc = acpicpu_sc[ci->ci_acpiid];
772
773 if (sc == NULL)
774 return ENXIO;
775
776 (void)memset(&buf, 0, sizeof(buf));
777
778 mutex_enter(&sc->sc_mtx);
779
780 for (len = 0, i = sc->sc_pstate_max; i < sc->sc_pstate_count; i++) {
781
782 if (sc->sc_pstate[i].ps_freq == 0)
783 continue;
784
785 len += snprintf(buf + len, sizeof(buf) - len, "%u%s",
786 sc->sc_pstate[i].ps_freq,
787 i < (sc->sc_pstate_count - 1) ? " " : "");
788 }
789
790 mutex_exit(&sc->sc_mtx);
791
792 node = *rnode;
793 node.sysctl_data = buf;
794
795 err = sysctl_lookup(SYSCTLFN_CALL(&node));
796
797 if (err != 0 || newp == NULL)
798 return err;
799
800 return 0;
801 }
802
803