The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/cpu.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2005-2007 Nate Lawson (SDG)
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    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.
   13  *
   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
   24  * SUCH DAMAGE.
   25  *
   26  * $FreeBSD: releng/8.3/sys/sys/cpu.h 199583 2009-11-20 15:27:52Z jhb $
   27  */
   28 
   29 #ifndef _SYS_CPU_H_
   30 #define _SYS_CPU_H_
   31 
   32 #include <sys/eventhandler.h>
   33 
   34 /*
   35  * CPU device support.
   36  */
   37 
   38 #define CPU_IVAR_PCPU           1
   39 #define CPU_IVAR_NOMINAL_MHZ    2
   40 
   41 static __inline struct pcpu *cpu_get_pcpu(device_t dev)
   42 {
   43         uintptr_t v = 0;
   44         BUS_READ_IVAR(device_get_parent(dev), dev, CPU_IVAR_PCPU, &v);
   45         return ((struct pcpu *)v);
   46 }
   47 
   48 static __inline int32_t cpu_get_nominal_mhz(device_t dev)
   49 {
   50         uintptr_t v = 0;
   51         if (BUS_READ_IVAR(device_get_parent(dev), dev,
   52             CPU_IVAR_NOMINAL_MHZ, &v) != 0)
   53                 return (-1);
   54         return ((int32_t)v);
   55 }
   56 
   57 /*
   58  * CPU frequency control interface.
   59  */
   60 
   61 /* Each driver's CPU frequency setting is exported in this format. */
   62 struct cf_setting {
   63         int     freq;   /* CPU clock in Mhz or 100ths of a percent. */
   64         int     volts;  /* Voltage in mV. */
   65         int     power;  /* Power consumed in mW. */
   66         int     lat;    /* Transition latency in us. */
   67         device_t dev;   /* Driver providing this setting. */
   68         int     spec[4];/* Driver-specific storage for non-standard info. */
   69 };
   70 
   71 /* Maximum number of settings a given driver can have. */
   72 #define MAX_SETTINGS            24
   73 
   74 /* A combination of settings is a level. */
   75 struct cf_level {
   76         struct cf_setting       total_set;
   77         struct cf_setting       abs_set;
   78         struct cf_setting       rel_set[MAX_SETTINGS];
   79         int                     rel_count;
   80         TAILQ_ENTRY(cf_level)   link;
   81 };
   82 
   83 TAILQ_HEAD(cf_level_lst, cf_level);
   84 
   85 /* Drivers should set all unknown values to this. */
   86 #define CPUFREQ_VAL_UNKNOWN     (-1)
   87 
   88 /*
   89  * Every driver offers a type of CPU control.  Absolute levels are mutually
   90  * exclusive while relative levels modify the current absolute level.  There
   91  * may be multiple absolute and relative drivers available on a given
   92  * system.
   93  *
   94  * For example, consider a system with two absolute drivers that provide
   95  * frequency settings of 100, 200 and 300, 400 and a relative driver that
   96  * provides settings of 50%, 100%.  The cpufreq core would export frequency
   97  * levels of 50, 100, 150, 200, 300, 400.
   98  *
   99  * The "info only" flag signifies that settings returned by
  100  * CPUFREQ_DRV_SETTINGS cannot be passed to the CPUFREQ_DRV_SET method and
  101  * are only informational.  This is for some drivers that can return
  102  * information about settings but rely on another machine-dependent driver
  103  * for actually performing the frequency transition (e.g., ACPI performance
  104  * states of type "functional fixed hardware.")
  105  */
  106 #define CPUFREQ_TYPE_MASK       0xffff
  107 #define CPUFREQ_TYPE_RELATIVE   (1<<0)
  108 #define CPUFREQ_TYPE_ABSOLUTE   (1<<1)
  109 #define CPUFREQ_FLAG_INFO_ONLY  (1<<16)
  110 
  111 /*
  112  * When setting a level, the caller indicates the priority of this request.
  113  * Priorities determine, among other things, whether a level can be
  114  * overridden by other callers.  For example, if the user sets a level but
  115  * the system thermal driver needs to override it for emergency cooling,
  116  * the driver would use a higher priority.  Once the event has passed, the
  117  * driver would call cpufreq to resume any previous level.
  118  */
  119 #define CPUFREQ_PRIO_HIGHEST    1000000
  120 #define CPUFREQ_PRIO_KERN       1000
  121 #define CPUFREQ_PRIO_USER       100
  122 #define CPUFREQ_PRIO_LOWEST     0
  123 
  124 /*
  125  * Register and unregister a driver with the cpufreq core.  Once a driver
  126  * is registered, it must support calls to its CPUFREQ_GET, CPUFREQ_GET_LEVEL,
  127  * and CPUFREQ_SET methods.  It must also unregister before returning from
  128  * its DEVICE_DETACH method.
  129  */
  130 int     cpufreq_register(device_t dev);
  131 int     cpufreq_unregister(device_t dev);
  132 
  133 /*
  134  * Notify the cpufreq core that the number of or values for settings have
  135  * changed.
  136  */
  137 int     cpufreq_settings_changed(device_t dev);
  138 
  139 /*
  140  * Eventhandlers that are called before and after a change in frequency.
  141  * The new level and the result of the change (0 is success) is passed in.
  142  * If the driver wishes to revoke the change from cpufreq_pre_change, it
  143  * stores a non-zero error code in the result parameter and the change will
  144  * not be made.  If the post-change eventhandler gets a non-zero result, 
  145  * no change was made and the previous level remains in effect.  If a change
  146  * is revoked, the post-change eventhandler is still called with the error
  147  * value supplied by the revoking driver.  This gives listeners who cached
  148  * some data in preparation for a level change a chance to clean up.
  149  */
  150 typedef void (*cpufreq_pre_notify_fn)(void *, const struct cf_level *, int *);
  151 typedef void (*cpufreq_post_notify_fn)(void *, const struct cf_level *, int);
  152 EVENTHANDLER_DECLARE(cpufreq_pre_change, cpufreq_pre_notify_fn);
  153 EVENTHANDLER_DECLARE(cpufreq_post_change, cpufreq_post_notify_fn);
  154 
  155 /*
  156  * Eventhandler called when the available list of levels changed.
  157  * The unit number of the device (i.e. "cpufreq0") whose levels changed
  158  * is provided so the listener can retrieve the new list of levels.
  159  */
  160 typedef void (*cpufreq_levels_notify_fn)(void *, int);
  161 EVENTHANDLER_DECLARE(cpufreq_levels_changed, cpufreq_levels_notify_fn);
  162 
  163 /* Allow values to be +/- a bit since sometimes we have to estimate. */
  164 #define CPUFREQ_CMP(x, y)       (abs((x) - (y)) < 25)
  165 
  166 /*
  167  * Machine-dependent functions.
  168  */
  169 
  170 /* Estimate the current clock rate for the given CPU id. */
  171 int     cpu_est_clockrate(int cpu_id, uint64_t *rate);
  172 
  173 #endif /* !_SYS_CPU_H_ */

Cache object: 75c134f6d2d5eb17a57e6f387edc1c50


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.