1/* $NetBSD: cpufreq.h,v 1.4 2011/10/25 11:35:49 jruoho Exp $ */ 2 3/*- 4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jukka Ruohonen. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32#ifndef _SYS_CPUFREQ_H_ 33#define _SYS_CPUFREQ_H_ 34 35#ifndef _KERNEL 36#include <stdbool.h> 37#endif 38 39#ifdef _KERNEL 40#ifndef _SYS_XCALL_H_ 41#include <sys/xcall.h> 42#endif 43#endif 44 45#define CPUFREQ_NAME_MAX 16 46#define CPUFREQ_STATE_MAX 32 47#define CPUFREQ_LATENCY_MAX UINT32_MAX 48 49#define CPUFREQ_STATE_ENABLED UINT32_MAX 50#define CPUFREQ_STATE_DISABLED UINT32_MAX - 1 51 52struct cpufreq_state { 53 uint32_t cfs_freq; /* MHz */ 54 uint32_t cfs_power; /* mW */ 55 uint32_t cfs_latency; /* usec */ 56 uint32_t cfs_index; 57 uint32_t cfs_reserved[5]; 58}; 59 60struct cpufreq { 61 char cf_name[CPUFREQ_NAME_MAX]; 62 uint32_t cf_state_count; 63 uint32_t cf_state_target; 64 uint32_t cf_state_current; 65 uint32_t cf_reserved[5]; 66 u_int cf_index; 67 68#ifdef _KERNEL 69 bool cf_mp; 70 bool cf_init; 71 void *cf_cookie; 72 xcfunc_t cf_get_freq; 73 xcfunc_t cf_set_freq; 74 uint32_t cf_state_saved; 75 struct cpufreq_state cf_state[CPUFREQ_STATE_MAX]; 76#endif /* _KERNEL */ 77}; 78 79#ifdef _KERNEL 80void cpufreq_init(void); 81int cpufreq_register(struct cpufreq *); 82void cpufreq_deregister(void); 83void cpufreq_suspend(struct cpu_info *); 84void cpufreq_resume(struct cpu_info *); 85uint32_t cpufreq_get(struct cpu_info *); 86int cpufreq_get_backend(struct cpufreq *); 87int cpufreq_get_state(uint32_t, struct cpufreq_state *); 88int cpufreq_get_state_index(uint32_t, struct cpufreq_state *); 89void cpufreq_set(struct cpu_info *, uint32_t); 90void cpufreq_set_all(uint32_t); 91#endif /* _KERNEL */ 92 93#endif /* _SYS_CPUFREQ_H_ */ 94