linux/drivers/cpuidle/driver.c
<<
ptio34./spa v2 34./formv2 34.a ptio34 href="../linux+v3e.310/drivers/cpuidle/driver.c">ptio34.img src="../.static/gfx/right.png" alt=">>">pt./spa v2pt.spa class="lxr_search">ptio ="+search" method="post" onsubmit="return do_search(this);">ptio34.input typ hidden" nam navtarget" ion> ">ptio34.input typ text" nam search" id search">ptio34.buttopttyp submit">Searchptio34Prefs2 34./a>pt./spa v2io34 4./divv2io34 4.form ac> ="ajax+*" method="post" onsubmit="return false;">pt.input typ hidden" nam ajax_lookup" id ajax_lookup" ion> ">pio34 4./formv2pio34 4.div class="headingbottom">2 .div id file_contents"v
4 41./a>.spa  class="comment">/*./spa v24 42./a>.spa  class="comment"> * driver.c - driver support./spa v24 43./a>.spa  class="comment"> *./spa v24 44./a>.spa  class="comment"> * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>./spa v24 45./a>.spa  class="comment"> *               Shaohua Li <shaohua.li@intel.com>./spa v24 46./a>.spa  class="comment"> *               Adam Belay <abelay@novell.com>./spa v24 47./a>.spa  class="comment"> *./spa v24 48./a>.spa  class="comment"> * This code is licenced under the GPL../spa v24 49./a>.spa  class="comment"> */./spa v24 84.1av24 11./a>#include <linux/mutex.h./a>>24 12./a>#include <linux/module.h./a>>24 13./a>#include <linux/cpuidle.h./a>>24 14.1av24 15./a>#include "cpuidle.h./a>"24 16.1av24 17./a>static struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a>;24 18./a>.a href="+code=DEFINE_SPINLOCK" class="sref">DEFINE_SPINLOCK./a>(.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24 19./a>int4.a href="+code=cpuidle_driver_refcount" class="sref">cpuidle_driver_refcount./a>;24 24.1av24 21./a>static void4.a href="+code=__cpuidle_register_driver" class="sref">__cpuidle_register_driver./a>(struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=drv" class="sref">drv./a>)24 22./a>{24 23./a>        int4.a href="+code=i" class="sref">i./a>;24 24./a>        .spa  class="comment">/*./spa v24 25./a>.spa  class="comment">         * cpuidle driver should set the drv->power_specified bit./spa v24 26./a>.spa  class="comment">         * before registering if the driver provides./spa v24 27./a>.spa  class="comment">         * power_usage numbers../spa v24 28./a>.spa  class="comment">         *./spa v24 29./a>.spa  class="comment">         * If power_specified is not set,./spa v24 30./a>.spa  class="comment">         * we fill in power_usage with decreasing ion>
s as the./spa v24 31./a>.spa  class="comment">         * cpuidle code has a  implicit assum23/optthat state Cn./spa v24 32./a>.spa  class="comment">         * us
s less powertthan C(n-1)../spa v24 33./a>.spa  class="comment">         *./spa v24 34./a>.spa  class="comment">         * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned./spa v24 35./a>.spa  class="comment">         * an power ion>
 of -1.  So we us
 -2, -3, etc, for other./spa v24 36./a>.spa  class="comment">         * c-states../spa v24 37./a>.spa  class="comment">         */./spa v24 38./a>        if (!.a href="+code=drv" class="sref">drv./a>->.a href="+code=power_specified" class="sref">power_specified./a>) {24 39./a>                for (.a href="+code=i" class="sref">i./a> =4.a href="+code=CPUIDLE_DRIVER_STATE_START" class="sref">CPUIDLE_DRIVER_STATE_START./a>;4.a href="+code=i" class="sref">i./a> <4.a href="+code=drv" class="sref">drv./a>->.a href="+code=state_count" class="sref">state_count./a>;4.a href="+code=i" class="sref">i./a>++)24 40./a>                        .a href="+code=drv" class="sref">drv./a>->.a href="+code=states" class="sref">states./a>[.a href="+code=i" class="sref">i./a>]..a href="+code=power_usage" class="sref">power_usage./a> =4-1 -4.a href="+code=i" class="sref">i./a>;24 41./a>        }24 42./a>}24 43.1av24 44.1av24 45./a>.spa  class="comment">/**./spa v24 46./a>.spa  class="comment"> * cpuidle_register_driver -4registers a driver./spa v24 47./a>.spa  class="comment"> * @drv: the driver./spa v24 48./a>.spa  class="comment"> */./spa v24 49./a>int4.a href="+code=cpuidle_register_driver" class="sref">cpuidle_register_driver./a>(struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=drv" class="sref">drv./a>)24 50./a>{24 51./a>        if (!.a href="+code=drv" class="sref">drv./a> || !.a href="+code=drv" class="sref">drv./a>->.a href="+code=state_count" class="sref">state_count./a>)24 52./a>                return -.a href="+code=EINVAL" class="sref">EINVAL./a>;24 53.1av24 54./a>        if (.a href="+code=cpuidle_disabled" class="sref">cpuidle_disabled./a>())24 55./a>                return -.a href="+code=ENODEV" class="sref">ENODEV./a>;24 56.1av24 57./a>        .a href="+code=spin_lock" class="sref">spin_lock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24 58./a>        if (.a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a>) {24 59./a>                .a href="+code=spin_unlock" class="sref">spin_unlock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24 60./a>                return -.a href="+code=EBUSY" class="sref">EBUSY./a>;24 61./a>        }24 62./a>        .a href="+code=__cpuidle_register_driver" class="sref">__cpuidle_register_driver./a>(.a href="+code=drv" class="sref">drv./a>);24 63./a>        .a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a> =4.a href="+code=drv" class="sref">drv./a>;24 64./a>        .a href="+code=spin_unlock" class="sref">spin_unlock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24 65.1av24 66./a>        return 0;24 67./a>}24 68.1av24 69./a>.a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL./a>(.a href="+code=cpuidle_register_driver" class="sref">cpuidle_register_driver./a>);24 74.1av24 71./a>.spa  class="comment">/**./spa v24 72./a>.spa  class="comment"> * cpuidle_get_driver -4return the current driver./spa v24 73./a>.spa  class="comment"> */./spa v24 74./a>struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=cpuidle_get_driver" class="sref">cpuidle_get_driver./a>(void)24 75./a>{24 76./a>        return .a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a>;24 77./a>}24 78./a>.a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL./a>(.a href="+code=cpuidle_get_driver" class="sref">cpuidle_get_driver./a>);24 79.1av24 80./a>.spa  class="comment">/**./spa v24 81./a>.spa  class="comment"> * cpuidle_unregister_driver -4unregisters a driver./spa v24 82./a>.spa  class="comment"> * @drv: the driver./spa v24 83./a>.spa  class="comment"> */./spa v24 84./a>void4.a href="+code=cpuidle_unregister_driver" class="sref">cpuidle_unregister_driver./a>(struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=drv" class="sref">drv./a>)24 85./a>{24 86./a>        if (.a href="+code=drv" class="sref">drv./a> !=4.a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a>) {24 87./a>                .a href="+code=WARN" class="sref">WARN./a>(1, .spa  class="string">"invalid4cpuidle_unregister_driver(%s)\n"4 88./a>                        .a href="+code=drv" class="sref">drv./a>->.a href="+code=nam
" class="sref">nam
./a>);24 89./a>                return;24 90./a>        }24 91.1av24 92./a>        .a href="+code=spin_lock" class="sref">spin_lock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24 93.1av24 94./a>        if (!.a href="+code=WARN_ON" class="sref">WARN_ON./a>(.a href="+code=cpuidle_driver_refcount" class="sref">cpuidle_driver_refcount./a> > 0))24 95./a>                .a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a> =4.a href="+code=NULL" class="sref">NULL./a>;24 96.1av24 97./a>        .a href="+code=spin_unlock" class="sref">spin_unlock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24 98./a>}24 99.1av24100./a>.a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL./a>(.a href="+code=cpuidle_unregister_driver" class="sref">cpuidle_unregister_driver./a>);24101.1av24102./a>struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=cpuidle_driver_ref" class="sref">cpuidle_driver_ref./a>(void)24103./a>{24104./a>        struct4.a href="+code=cpuidle_driver" class="sref">cpuidle_driver./a> *.a href="+code=drv" class="sref">drv./a>;24105.1av24106./a>        .a href="+code=spin_lock" class="sref">spin_lock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24107.1av24108./a>        .a href="+code=drv" class="sref">drv./a> =4.a href="+code=cpuidle_curr_driver" class="sref">cpuidle_curr_driver./a>;24109./a>        .a href="+code=cpuidle_driver_refcount" class="sref">cpuidle_driver_refcount./a>++;24184.1av24111./a>        .a href="+code=spin_unlock" class="sref">spin_unlock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24112./a>        return .a href="+code=drv" class="sref">drv./a>;24113./a>}24114.1av24115./a>void4.a href="+code=cpuidle_driver_unref" class="sref">cpuidle_driver_unref./a>(void)24116.1av{24117./a>        .a href="+code=spin_lock" class="sref">spin_lock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24118.1av24119./a>        if (!.a href="+code=WARN_ON" class="sref">WARN_ON./a>(.a href="+code=cpuidle_driver_refcount" class="sref">cpuidle_driver_refcount./a> <= 0))24120./a>                .a href="+code=cpuidle_driver_refcount" class="sref">cpuidle_driver_refcount./a>--;24121.1av24122./a>        .a href="+code=spin_unlock" class="sref">spin_unlock./a>(&.a href="+code=cpuidle_driver_lock" class="sref">cpuidle_driver_lock./a>);24123./a>}24124./a>
The original LXR software by the LXR community./a>, this experimental vers/optby lxr@linux.no./a>. ./divv2.div class="subfooter"> lxr.linux.no kindly hostedtby Redpill Linpro AS./a>, provider of Linux consulting and opera3/ops services since 1995. ./divv2 ./bodyv2./htmlv2