2 * Copyright (c) 2005 Nate Lawson (SDG)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #define CPU_IVAR_PCPU 1
38 static __inline struct pcpu *cpu_get_pcpu(device_t dev)
41 BUS_READ_IVAR(device_get_parent(dev), dev, CPU_IVAR_PCPU, &v);
42 return ((struct pcpu *)v);
46 * CPU frequency control interface.
49 /* Each driver's CPU frequency setting is exported in this format. */
51 int freq; /* CPU clock in Mhz or 100ths of a percent. */
52 int volts; /* Voltage in mV. */
53 int power; /* Power consumed in mW. */
54 int lat; /* Transition latency in us. */
55 device_t dev; /* Driver providing this setting. */
56 int spec[4];/* Driver-specific storage for non-standard info. */
59 /* Maximum number of settings a given driver can have. */
60 #define MAX_SETTINGS 24
62 /* A combination of settings is a level. */
64 struct cf_setting total_set;
65 struct cf_setting abs_set;
66 struct cf_setting rel_set[MAX_SETTINGS];
68 TAILQ_ENTRY(cf_level) link;
71 TAILQ_HEAD(cf_level_lst, cf_level);
73 /* Drivers should set all unknown values to this. */
74 #define CPUFREQ_VAL_UNKNOWN (-1)
77 * Every driver offers a type of CPU control. Absolute levels are mutually
78 * exclusive while relative levels modify the current absolute level. There
79 * may be multiple absolute and relative drivers available on a given
82 * For example, consider a system with two absolute drivers that provide
83 * frequency settings of 100, 200 and 300, 400 and a relative driver that
84 * provides settings of 50%, 100%. The cpufreq core would export frequency
85 * levels of 50, 100, 150, 200, 300, 400.
87 * The "info only" flag signifies that settings returned by
88 * CPUFREQ_DRV_SETTINGS cannot be passed to the CPUFREQ_DRV_SET method and
89 * are only informational. This is for some drivers that can return
90 * information about settings but rely on another machine-dependent driver
91 * for actually performing the frequency transition (e.g., ACPI performance
92 * states of type "functional fixed hardware.")
94 #define CPUFREQ_TYPE_MASK 0xffff
95 #define CPUFREQ_TYPE_RELATIVE (1<<0)
96 #define CPUFREQ_TYPE_ABSOLUTE (1<<1)
97 #define CPUFREQ_FLAG_INFO_ONLY (1<<16)
100 * When setting a level, the caller indicates the priority of this request.
101 * Priorities determine, among other things, whether a level can be
102 * overridden by other callers. For example, if the user sets a level but
103 * the system thermal driver needs to override it for emergency cooling,
104 * the driver would use a higher priority. Once the event has passed, the
105 * driver would call cpufreq to resume any previous level.
107 #define CPUFREQ_PRIO_HIGHEST 1000000
108 #define CPUFREQ_PRIO_KERN 1000
109 #define CPUFREQ_PRIO_USER 100
110 #define CPUFREQ_PRIO_LOWEST 0
113 * Register and unregister a driver with the cpufreq core. Once a driver
114 * is registered, it must support calls to its CPUFREQ_GET, CPUFREQ_GET_LEVEL,
115 * and CPUFREQ_SET methods. It must also unregister before returning from
116 * its DEVICE_DETACH method.
118 int cpufreq_register(device_t dev);
119 int cpufreq_unregister(device_t dev);
121 /* Allow values to be +/- a bit since sometimes we have to estimate. */
122 #define CPUFREQ_CMP(x, y) (abs((x) - (y)) < 25)
125 * Machine-dependent functions.
128 /* Estimate the current clock rate for the given CPU id. */
129 int cpu_est_clockrate(int cpu_id, uint64_t *rate);
131 #endif /* !_SYS_CPU_H_ */