Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * governor.h - internal header for devfreq governors.
0004  *
0005  * Copyright (C) 2011 Samsung Electronics
0006  *  MyungJoo Ham <myungjoo.ham@samsung.com>
0007  *
0008  * This header is for devfreq governors in drivers/devfreq/
0009  */
0010 
0011 #ifndef _GOVERNOR_H
0012 #define _GOVERNOR_H
0013 
0014 #include <linux/devfreq.h>
0015 
0016 #define DEVFREQ_NAME_LEN            16
0017 
0018 #define to_devfreq(DEV) container_of((DEV), struct devfreq, dev)
0019 
0020 /* Devfreq events */
0021 #define DEVFREQ_GOV_START           0x1
0022 #define DEVFREQ_GOV_STOP            0x2
0023 #define DEVFREQ_GOV_UPDATE_INTERVAL     0x3
0024 #define DEVFREQ_GOV_SUSPEND         0x4
0025 #define DEVFREQ_GOV_RESUME          0x5
0026 
0027 #define DEVFREQ_MIN_FREQ            0
0028 #define DEVFREQ_MAX_FREQ            ULONG_MAX
0029 
0030 /*
0031  * Definition of the governor feature flags
0032  * - DEVFREQ_GOV_FLAG_IMMUTABLE
0033  *   : This governor is never changeable to other governors.
0034  * - DEVFREQ_GOV_FLAG_IRQ_DRIVEN
0035  *   : The devfreq won't schedule the work for this governor.
0036  */
0037 #define DEVFREQ_GOV_FLAG_IMMUTABLE          BIT(0)
0038 #define DEVFREQ_GOV_FLAG_IRQ_DRIVEN         BIT(1)
0039 
0040 /*
0041  * Definition of governor attribute flags except for common sysfs attributes
0042  * - DEVFREQ_GOV_ATTR_POLLING_INTERVAL
0043  *   : Indicate polling_interval sysfs attribute
0044  * - DEVFREQ_GOV_ATTR_TIMER
0045  *   : Indicate timer sysfs attribute
0046  */
0047 #define DEVFREQ_GOV_ATTR_POLLING_INTERVAL       BIT(0)
0048 #define DEVFREQ_GOV_ATTR_TIMER              BIT(1)
0049 
0050 /**
0051  * struct devfreq_cpu_data - Hold the per-cpu data
0052  * @node:   list node
0053  * @dev:    reference to cpu device.
0054  * @first_cpu:  the cpumask of the first cpu of a policy.
0055  * @opp_table:  reference to cpu opp table.
0056  * @cur_freq:   the current frequency of the cpu.
0057  * @min_freq:   the min frequency of the cpu.
0058  * @max_freq:   the max frequency of the cpu.
0059  *
0060  * This structure stores the required cpu_data of a cpu.
0061  * This is auto-populated by the governor.
0062  */
0063 struct devfreq_cpu_data {
0064     struct list_head node;
0065 
0066     struct device *dev;
0067     unsigned int first_cpu;
0068 
0069     struct opp_table *opp_table;
0070     unsigned int cur_freq;
0071     unsigned int min_freq;
0072     unsigned int max_freq;
0073 };
0074 
0075 /**
0076  * struct devfreq_governor - Devfreq policy governor
0077  * @node:       list node - contains registered devfreq governors
0078  * @name:       Governor's name
0079  * @attrs:      Governor's sysfs attribute flags
0080  * @flags:      Governor's feature flags
0081  * @get_target_freq:    Returns desired operating frequency for the device.
0082  *          Basically, get_target_freq will run
0083  *          devfreq_dev_profile.get_dev_status() to get the
0084  *          status of the device (load = busy_time / total_time).
0085  * @event_handler:      Callback for devfreq core framework to notify events
0086  *                      to governors. Events include per device governor
0087  *                      init and exit, opp changes out of devfreq, suspend
0088  *                      and resume of per device devfreq during device idle.
0089  *
0090  * Note that the callbacks are called with devfreq->lock locked by devfreq.
0091  */
0092 struct devfreq_governor {
0093     struct list_head node;
0094 
0095     const char name[DEVFREQ_NAME_LEN];
0096     const u64 attrs;
0097     const u64 flags;
0098     int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
0099     int (*event_handler)(struct devfreq *devfreq,
0100                 unsigned int event, void *data);
0101 };
0102 
0103 void devfreq_monitor_start(struct devfreq *devfreq);
0104 void devfreq_monitor_stop(struct devfreq *devfreq);
0105 void devfreq_monitor_suspend(struct devfreq *devfreq);
0106 void devfreq_monitor_resume(struct devfreq *devfreq);
0107 void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);
0108 
0109 int devfreq_add_governor(struct devfreq_governor *governor);
0110 int devfreq_remove_governor(struct devfreq_governor *governor);
0111 
0112 int devm_devfreq_add_governor(struct device *dev,
0113                   struct devfreq_governor *governor);
0114 
0115 int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);
0116 int devfreq_update_target(struct devfreq *devfreq, unsigned long freq);
0117 void devfreq_get_freq_range(struct devfreq *devfreq, unsigned long *min_freq,
0118                 unsigned long *max_freq);
0119 
0120 static inline int devfreq_update_stats(struct devfreq *df)
0121 {
0122     if (!df->profile->get_dev_status)
0123         return -EINVAL;
0124 
0125     return df->profile->get_dev_status(df->dev.parent, &df->last_status);
0126 }
0127 #endif /* _GOVERNOR_H */