| /* |
| * This module exposes the interface to kernel space for specifying |
| * QoS dependencies. It provides infrastructure for registration of: |
| * |
| * Dependents on a QoS value : register requests |
| * Watchers of QoS value : get notified when target QoS value changes |
| * |
| * This QoS design is best effort based. Dependents register their QoS needs. |
| * Watchers register to keep track of the current QoS needs of the system. |
| * |
| * There are 3 basic classes of QoS parameter: latency, timeout, throughput |
| * each have defined units: |
| * latency: usec |
| * timeout: usec <-- currently not used. |
| * throughput: kbs (kilo byte / sec) |
| * |
| * There are lists of pm_qos_objects each one wrapping requests, notifiers |
| * |
| * User mode requests on a QOS parameter register themselves to the |
| * subsystem by opening the device node /dev/... and writing there request to |
| * the node. As long as the process holds a file handle open to the node the |
| * client continues to be accounted for. Upon file release the usermode |
| * request is removed and a new qos target is computed. This way when the |
| * request that the application has is cleaned up when closes the file |
| * pointer or exits the pm_qos_object will get an opportunity to clean up. |
| * |
| * Mark Gross <mgross@linux.intel.com> |
| */ |
| |
| /*#define DEBUG*/ |
| |
| #include <linux/pm_qos.h> |
| #include <linux/sched.h> |
| #include <linux/spinlock.h> |
| #include <linux/slab.h> |
| #include <linux/time.h> |
| #include <linux/fs.h> |
| #include <linux/device.h> |
| #include <linux/miscdevice.h> |
| #include <linux/string.h> |
| #include <linux/platform_device.h> |
| #include <linux/init.h> |
| #include <linux/kernel.h> |
| #include <linux/debugfs.h> |
| #include <linux/seq_file.h> |
| |
| #include <linux/uaccess.h> |
| #include <linux/export.h> |
| #include <trace/events/power.h> |
| |
| /* |
| * locking rule: all changes to constraints or notifiers lists |
| * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock |
| * held, taken with _irqsave. One lock to rule them all |
| */ |
| struct pm_qos_object { |
| struct pm_qos_constraints *constraints; |
| struct miscdevice pm_qos_power_miscdev; |
| char *name; |
| }; |
| |
| static DEFINE_SPINLOCK(pm_qos_lock); |
| |
| static struct pm_qos_object null_pm_qos; |
| |
| static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); |
| static struct pm_qos_constraints cpu_dma_constraints = { |
| .req_list = LIST_HEAD_INIT(cpu_dma_constraints.req_list), |
| .list = PLIST_HEAD_INIT(cpu_dma_constraints.list), |
| .target_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE, |
| .default_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = __MUTEX_INITIALIZER(cpu_dma_constraints.qos_lock), |
| .notifiers = &cpu_dma_lat_notifier, |
| }; |
| static struct pm_qos_object cpu_dma_pm_qos = { |
| .constraints = &cpu_dma_constraints, |
| .name = "cpu_dma_latency", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); |
| static struct pm_qos_constraints network_lat_constraints = { |
| .req_list = LIST_HEAD_INIT(network_lat_constraints.req_list), |
| .list = PLIST_HEAD_INIT(network_lat_constraints.list), |
| .target_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE, |
| .default_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = __MUTEX_INITIALIZER(network_lat_constraints.qos_lock), |
| .notifiers = &network_lat_notifier, |
| }; |
| static struct pm_qos_object network_lat_pm_qos = { |
| .constraints = &network_lat_constraints, |
| .name = "network_latency", |
| }; |
| |
| |
| static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); |
| static struct pm_qos_constraints network_tput_constraints = { |
| .req_list = LIST_HEAD_INIT(network_tput_constraints.req_list), |
| .list = PLIST_HEAD_INIT(network_tput_constraints.list), |
| .target_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE, |
| .default_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(network_tput_constraints.qos_lock), |
| .notifiers = &network_throughput_notifier, |
| }; |
| static struct pm_qos_object network_throughput_pm_qos = { |
| .constraints = &network_tput_constraints, |
| .name = "network_throughput", |
| }; |
| |
| |
| static BLOCKING_NOTIFIER_HEAD(memory_bandwidth_notifier); |
| static struct pm_qos_constraints memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(memory_bw_constraints.list), |
| .target_value = PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(memory_bw_constraints.qos_lock), |
| .notifiers = &memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object memory_bandwidth_pm_qos = { |
| .constraints = &memory_bw_constraints, |
| .name = "memory_bandwidth", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(disp_freq_notifier); |
| static struct pm_qos_constraints disp_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(disp_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(disp_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(disp_freq_constraints.qos_lock), |
| .notifiers = &disp_freq_notifier, |
| }; |
| static struct pm_qos_object disp_freq_pm_qos = { |
| .constraints = &disp_freq_constraints, |
| .name = "disp_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(mdp_freq_notifier); |
| static struct pm_qos_constraints mdp_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(mdp_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(mdp_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(mdp_freq_constraints.qos_lock), |
| .notifiers = &mdp_freq_notifier, |
| }; |
| static struct pm_qos_object mdp_freq_pm_qos = { |
| .constraints = &mdp_freq_constraints, |
| .name = "mdp_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(vdec_freq_notifier); |
| static struct pm_qos_constraints vdec_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(vdec_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(vdec_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(vdec_freq_constraints.qos_lock), |
| .notifiers = &vdec_freq_notifier, |
| }; |
| static struct pm_qos_object vdec_freq_pm_qos = { |
| .constraints = &vdec_freq_constraints, |
| .name = "vdec_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(venc_freq_notifier); |
| static struct pm_qos_constraints venc_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(venc_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(venc_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(venc_freq_constraints.qos_lock), |
| .notifiers = &venc_freq_notifier, |
| }; |
| static struct pm_qos_object venc_freq_pm_qos = { |
| .constraints = &venc_freq_constraints, |
| .name = "venc_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(img_freq_notifier); |
| static struct pm_qos_constraints img_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(img_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(img_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(img_freq_constraints.qos_lock), |
| .notifiers = &img_freq_notifier, |
| }; |
| static struct pm_qos_object img_freq_pm_qos = { |
| .constraints = &img_freq_constraints, |
| .name = "img_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(cam_freq_notifier); |
| static struct pm_qos_constraints cam_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(cam_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(cam_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(cam_freq_constraints.qos_lock), |
| .notifiers = &cam_freq_notifier, |
| }; |
| static struct pm_qos_object cam_freq_pm_qos = { |
| .constraints = &cam_freq_constraints, |
| .name = "cam_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(dpe_freq_notifier); |
| static struct pm_qos_constraints dpe_freq_constraints = { |
| .req_list = LIST_HEAD_INIT(dpe_freq_constraints.req_list), |
| .list = PLIST_HEAD_INIT(dpe_freq_constraints.list), |
| .target_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_FREQ_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(dpe_freq_constraints.qos_lock), |
| .notifiers = &dpe_freq_notifier, |
| }; |
| static struct pm_qos_object dpe_freq_pm_qos = { |
| .constraints = &dpe_freq_constraints, |
| .name = "dpe_freq", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(cpu_memory_bandwidth_notifier); |
| static struct pm_qos_constraints cpu_memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(cpu_memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(cpu_memory_bw_constraints.list), |
| .target_value = PM_QOS_CPU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_CPU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_CPU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(cpu_memory_bw_constraints.qos_lock), |
| .notifiers = &cpu_memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object cpu_memory_bandwidth_pm_qos = { |
| .constraints = &cpu_memory_bw_constraints, |
| .name = "cpu_memory_bandwidth", |
| }; |
| |
| |
| static BLOCKING_NOTIFIER_HEAD(gpu_memory_bandwidth_notifier); |
| static struct pm_qos_constraints gpu_memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(gpu_memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(gpu_memory_bw_constraints.list), |
| .target_value = PM_QOS_GPU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_GPU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_GPU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(gpu_memory_bw_constraints.qos_lock), |
| .notifiers = &gpu_memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object gpu_memory_bandwidth_pm_qos = { |
| .constraints = &gpu_memory_bw_constraints, |
| .name = "gpu_memory_bandwidth", |
| }; |
| |
| |
| static BLOCKING_NOTIFIER_HEAD(mm_memory_bandwidth_notifier); |
| static struct pm_qos_constraints mm_memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(mm_memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(mm_memory_bw_constraints.list), |
| .target_value = PM_QOS_MM_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(mm_memory_bw_constraints.qos_lock), |
| .notifiers = &mm_memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object mm_memory_bandwidth_pm_qos = { |
| .constraints = &mm_memory_bw_constraints, |
| .name = "mm_memory_bandwidth", |
| }; |
| |
| |
| static BLOCKING_NOTIFIER_HEAD(md_peri_memory_bandwidth_notifier); |
| static struct pm_qos_constraints md_peri_memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(md_peri_memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(md_peri_memory_bw_constraints.list), |
| .target_value = PM_QOS_MD_PERI_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_MD_PERI_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MD_PERI_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(md_peri_memory_bw_constraints.qos_lock), |
| .notifiers = &md_peri_memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object md_peri_memory_bandwidth_pm_qos = { |
| .constraints = &md_peri_memory_bw_constraints, |
| .name = "md_peri_memory_bandwidth", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(other_memory_bandwidth_notifier); |
| static struct pm_qos_constraints other_memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(other_memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(other_memory_bw_constraints.list), |
| .target_value = PM_QOS_OTHER_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_OTHER_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_OTHER_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(other_memory_bw_constraints.qos_lock), |
| .notifiers = &other_memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object other_memory_bandwidth_pm_qos = { |
| .constraints = &other_memory_bw_constraints, |
| .name = "other_memory_bandwidth", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(mm0_bandwidth_limiter_notifier); |
| static struct pm_qos_constraints mm0_bw_limiter_constraints = { |
| .req_list = LIST_HEAD_INIT(mm0_bw_limiter_constraints.req_list), |
| .list = PLIST_HEAD_INIT(mm0_bw_limiter_constraints.list), |
| .target_value = PM_QOS_MM_BANDWIDTH_LIMITER_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_BANDWIDTH_LIMITER_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_BANDWIDTH_LIMITER_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(mm0_bw_limiter_constraints.qos_lock), |
| .notifiers = &mm0_bandwidth_limiter_notifier, |
| }; |
| static struct pm_qos_object mm0_bandwidth_limiter_pm_qos = { |
| .constraints = &mm0_bw_limiter_constraints, |
| .name = "mm0_bandwidth_limiter", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(mm1_bandwidth_limiter_notifier); |
| static struct pm_qos_constraints mm1_bw_limiter_constraints = { |
| .req_list = LIST_HEAD_INIT(mm1_bw_limiter_constraints.req_list), |
| .list = PLIST_HEAD_INIT(mm1_bw_limiter_constraints.list), |
| .target_value = PM_QOS_MM_BANDWIDTH_LIMITER_DEFAULT_VALUE, |
| .default_value = PM_QOS_MM_BANDWIDTH_LIMITER_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_MM_BANDWIDTH_LIMITER_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(mm1_bw_limiter_constraints.qos_lock), |
| .notifiers = &mm1_bandwidth_limiter_notifier, |
| }; |
| static struct pm_qos_object mm1_bandwidth_limiter_pm_qos = { |
| .constraints = &mm1_bw_limiter_constraints, |
| .name = "mm1_bandwidth_limiter", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(emi_opp_notifier); |
| static struct pm_qos_constraints emi_opp_constraints = { |
| .req_list = LIST_HEAD_INIT(emi_opp_constraints.req_list), |
| .list = PLIST_HEAD_INIT(emi_opp_constraints.list), |
| .target_value = PM_QOS_EMI_OPP_DEFAULT_VALUE, |
| .default_value = PM_QOS_EMI_OPP_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_EMI_OPP_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = __MUTEX_INITIALIZER(emi_opp_constraints.qos_lock), |
| .notifiers = &emi_opp_notifier, |
| }; |
| static struct pm_qos_object emi_opp_pm_qos = { |
| .constraints = &emi_opp_constraints, |
| .name = "emi_opp", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(ddr_opp_notifier); |
| static struct pm_qos_constraints ddr_opp_constraints = { |
| .req_list = LIST_HEAD_INIT(ddr_opp_constraints.req_list), |
| .list = PLIST_HEAD_INIT(ddr_opp_constraints.list), |
| .target_value = PM_QOS_DDR_OPP_DEFAULT_VALUE, |
| .default_value = PM_QOS_DDR_OPP_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_DDR_OPP_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = __MUTEX_INITIALIZER(ddr_opp_constraints.qos_lock), |
| .notifiers = &ddr_opp_notifier, |
| }; |
| static struct pm_qos_object ddr_opp_pm_qos = { |
| .constraints = &ddr_opp_constraints, |
| .name = "ddr_opp", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(vcore_opp_notifier); |
| static struct pm_qos_constraints vcore_opp_constraints = { |
| .req_list = LIST_HEAD_INIT(vcore_opp_constraints.req_list), |
| .list = PLIST_HEAD_INIT(vcore_opp_constraints.list), |
| .target_value = PM_QOS_VCORE_OPP_DEFAULT_VALUE, |
| .default_value = PM_QOS_VCORE_OPP_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_VCORE_OPP_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = __MUTEX_INITIALIZER(vcore_opp_constraints.qos_lock), |
| .notifiers = &vcore_opp_notifier, |
| }; |
| static struct pm_qos_object vcore_opp_pm_qos = { |
| .constraints = &vcore_opp_constraints, |
| .name = "vcore_opp", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(vcore_dvfs_fixed_opp_notifier); |
| static struct pm_qos_constraints vcore_dvfs_fixed_opp_constraints = { |
| .req_list = LIST_HEAD_INIT(vcore_dvfs_fixed_opp_constraints.req_list), |
| .list = PLIST_HEAD_INIT(vcore_dvfs_fixed_opp_constraints.list), |
| .target_value = PM_QOS_VCORE_DVFS_FIXED_OPP_DEFAULT_VALUE, |
| .default_value = PM_QOS_VCORE_DVFS_FIXED_OPP_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_VCORE_DVFS_FIXED_OPP_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = |
| __MUTEX_INITIALIZER(vcore_dvfs_fixed_opp_constraints.qos_lock), |
| .notifiers = &vcore_dvfs_fixed_opp_notifier, |
| }; |
| static struct pm_qos_object vcore_dvfs_fixed_opp_pm_qos = { |
| .constraints = &vcore_dvfs_fixed_opp_constraints, |
| .name = "vcore_dvfs_fixed_opp", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(scp_vcore_req_notifier); |
| static struct pm_qos_constraints scp_vcore_req_constraints = { |
| .req_list = LIST_HEAD_INIT(scp_vcore_req_constraints.req_list), |
| .list = PLIST_HEAD_INIT(scp_vcore_req_constraints.list), |
| .target_value = PM_QOS_SCP_VCORE_REQUEST_DEFAULT_VALUE, |
| .default_value = PM_QOS_SCP_VCORE_REQUEST_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_SCP_VCORE_REQUEST_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = __MUTEX_INITIALIZER(scp_vcore_req_constraints.qos_lock), |
| .notifiers = &scp_vcore_req_notifier, |
| }; |
| static struct pm_qos_object scp_vcore_req_pm_qos = { |
| .constraints = &scp_vcore_req_constraints, |
| .name = "scp_vcore_req", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(power_model_ddr_req_notifier); |
| static struct pm_qos_constraints power_model_ddr_req_constraints = { |
| .req_list = LIST_HEAD_INIT(power_model_ddr_req_constraints.req_list), |
| .list = PLIST_HEAD_INIT(power_model_ddr_req_constraints.list), |
| .target_value = PM_QOS_POWER_MODEL_DDR_REQUEST_DEFAULT_VALUE, |
| .default_value = PM_QOS_POWER_MODEL_DDR_REQUEST_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_POWER_MODEL_DDR_REQUEST_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = |
| __MUTEX_INITIALIZER(power_model_ddr_req_constraints.qos_lock), |
| .notifiers = &power_model_ddr_req_notifier, |
| }; |
| static struct pm_qos_object power_model_ddr_req_pm_qos = { |
| .constraints = &power_model_ddr_req_constraints, |
| .name = "power_model_ddr_req", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(power_model_vcore_req_notifier); |
| static struct pm_qos_constraints power_model_vcore_req_constraints = { |
| .req_list = LIST_HEAD_INIT(power_model_vcore_req_constraints.req_list), |
| .list = PLIST_HEAD_INIT(power_model_vcore_req_constraints.list), |
| .target_value = PM_QOS_POWER_MODEL_VCORE_REQUEST_DEFAULT_VALUE, |
| .default_value = PM_QOS_POWER_MODEL_VCORE_REQUEST_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_POWER_MODEL_VCORE_REQUEST_DEFAULT_VALUE, |
| .type = PM_QOS_MAX, |
| .qos_lock = |
| __MUTEX_INITIALIZER(power_model_vcore_req_constraints.qos_lock), |
| .notifiers = &power_model_vcore_req_notifier, |
| }; |
| static struct pm_qos_object power_model_vcore_req_pm_qos = { |
| .constraints = &power_model_vcore_req_constraints, |
| .name = "power_model_vcore_req", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(vcore_dvfs_force_opp_notifier); |
| static struct pm_qos_constraints vcore_dvfs_force_opp_constraints = { |
| .req_list = LIST_HEAD_INIT(vcore_dvfs_force_opp_constraints.req_list), |
| .list = PLIST_HEAD_INIT(vcore_dvfs_force_opp_constraints.list), |
| .target_value = PM_QOS_VCORE_DVFS_FORCE_OPP_DEFAULT_VALUE, |
| .default_value = PM_QOS_VCORE_DVFS_FORCE_OPP_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_VCORE_DVFS_FORCE_OPP_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = |
| __MUTEX_INITIALIZER(vcore_dvfs_force_opp_constraints.qos_lock), |
| .notifiers = &vcore_dvfs_force_opp_notifier, |
| }; |
| static struct pm_qos_object vcore_dvfs_force_opp_pm_qos = { |
| .constraints = &vcore_dvfs_force_opp_constraints, |
| .name = "vcore_dvfs_force_opp", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(isp_hrt_bandwidth_notifier); |
| static struct pm_qos_constraints isp_hrt_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(isp_hrt_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(isp_hrt_bw_constraints.list), |
| .target_value = PM_QOS_ISP_HRT_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_ISP_HRT_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_ISP_HRT_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(isp_hrt_bw_constraints.qos_lock), |
| .notifiers = &isp_hrt_bandwidth_notifier, |
| }; |
| static struct pm_qos_object isp_hrt_bandwidth_pm_qos = { |
| .constraints = &isp_hrt_bw_constraints, |
| .name = "isp_hrt_bandwidth", |
| }; |
| |
| static BLOCKING_NOTIFIER_HEAD(apu_memory_bandwidth_notifier); |
| static struct pm_qos_constraints apu_memory_bw_constraints = { |
| .req_list = LIST_HEAD_INIT(apu_memory_bw_constraints.req_list), |
| .list = PLIST_HEAD_INIT(apu_memory_bw_constraints.list), |
| .target_value = PM_QOS_APU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .default_value = PM_QOS_APU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_APU_MEMORY_BANDWIDTH_DEFAULT_VALUE, |
| .type = PM_QOS_SUM, |
| .qos_lock = __MUTEX_INITIALIZER(apu_memory_bw_constraints.qos_lock), |
| .notifiers = &apu_memory_bandwidth_notifier, |
| }; |
| static struct pm_qos_object apu_memory_bandwidth_pm_qos = { |
| .constraints = &apu_memory_bw_constraints, |
| .name = "apu_memory_bandwidth", |
| }; |
| static BLOCKING_NOTIFIER_HEAD(vvpu_opp_notifier); |
| static struct pm_qos_constraints vvpu_opp_constraints = { |
| .req_list = LIST_HEAD_INIT(vvpu_opp_constraints.req_list), |
| .list = PLIST_HEAD_INIT(vvpu_opp_constraints.list), |
| .target_value = PM_QOS_VVPU_OPP_DEFAULT_VALUE, |
| .default_value = PM_QOS_VVPU_OPP_DEFAULT_VALUE, |
| .no_constraint_value = PM_QOS_VVPU_OPP_DEFAULT_VALUE, |
| .type = PM_QOS_MIN, |
| .qos_lock = __MUTEX_INITIALIZER(vvpu_opp_constraints.qos_lock), |
| .notifiers = &vvpu_opp_notifier, |
| }; |
| static struct pm_qos_object vvpu_opp_pm_qos = { |
| .constraints = &vvpu_opp_constraints, |
| .name = "vvpu_opp", |
| }; |
| |
| |
| static struct pm_qos_object *pm_qos_array[] = { |
| &null_pm_qos, |
| &cpu_dma_pm_qos, |
| &network_lat_pm_qos, |
| &network_throughput_pm_qos, |
| &memory_bandwidth_pm_qos, |
| |
| &cpu_memory_bandwidth_pm_qos, |
| &gpu_memory_bandwidth_pm_qos, |
| &mm_memory_bandwidth_pm_qos, |
| &md_peri_memory_bandwidth_pm_qos, |
| &other_memory_bandwidth_pm_qos, |
| &mm0_bandwidth_limiter_pm_qos, |
| &mm1_bandwidth_limiter_pm_qos, |
| |
| &ddr_opp_pm_qos, |
| &emi_opp_pm_qos, |
| &vcore_opp_pm_qos, |
| &vcore_dvfs_fixed_opp_pm_qos, |
| &scp_vcore_req_pm_qos, |
| &power_model_ddr_req_pm_qos, |
| &power_model_vcore_req_pm_qos, |
| &vcore_dvfs_force_opp_pm_qos, |
| |
| &disp_freq_pm_qos, |
| &mdp_freq_pm_qos, |
| &vdec_freq_pm_qos, |
| &venc_freq_pm_qos, |
| &img_freq_pm_qos, |
| &cam_freq_pm_qos, |
| &dpe_freq_pm_qos, |
| &isp_hrt_bandwidth_pm_qos, |
| &apu_memory_bandwidth_pm_qos, |
| &vvpu_opp_pm_qos, |
| }; |
| |
| static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, |
| size_t count, loff_t *f_pos); |
| static ssize_t pm_qos_power_read(struct file *filp, char __user *buf, |
| size_t count, loff_t *f_pos); |
| static int pm_qos_power_open(struct inode *inode, struct file *filp); |
| static int pm_qos_power_release(struct inode *inode, struct file *filp); |
| |
| static const struct file_operations pm_qos_power_fops = { |
| .write = pm_qos_power_write, |
| .read = pm_qos_power_read, |
| .open = pm_qos_power_open, |
| .release = pm_qos_power_release, |
| .llseek = noop_llseek, |
| }; |
| |
| /* unlocked internal variant */ |
| static inline int pm_qos_get_value(struct pm_qos_constraints *c) |
| { |
| struct plist_node *node; |
| int total_value = 0; |
| |
| if (plist_head_empty(&c->list)) |
| return c->no_constraint_value; |
| |
| switch (c->type) { |
| case PM_QOS_MIN: |
| return plist_first(&c->list)->prio; |
| |
| case PM_QOS_MAX: |
| return plist_last(&c->list)->prio; |
| |
| case PM_QOS_SUM: |
| plist_for_each(node, &c->list) |
| total_value += node->prio; |
| |
| return total_value; |
| |
| default: |
| /* runtime check for not using enum */ |
| BUG(); |
| return PM_QOS_DEFAULT_VALUE; |
| } |
| } |
| |
| s32 pm_qos_read_value(struct pm_qos_constraints *c) |
| { |
| return c->target_value; |
| } |
| |
| static inline void pm_qos_set_value(struct pm_qos_constraints *c, s32 value) |
| { |
| c->target_value = value; |
| } |
| |
| void pm_qos_trace_dbg_show_request(int pm_qos_class) |
| { |
| struct pm_qos_constraints *c; |
| struct pm_qos_request *req; |
| unsigned long flags; |
| struct list_head *l; |
| |
| if (pm_qos_class < PM_QOS_RESERVED |
| || pm_qos_class >= PM_QOS_NUM_CLASSES) |
| return; |
| |
| c = pm_qos_array[pm_qos_class]->constraints; |
| |
| spin_lock_irqsave(&pm_qos_lock, flags); |
| /* dump owner information*/ |
| list_for_each(l, &c->req_list) { |
| req = list_entry(l, struct pm_qos_request, list_node); |
| trace_pm_qos_update_request(req->pm_qos_class, |
| req->node.prio, req->owner); |
| } |
| spin_unlock_irqrestore(&pm_qos_lock, flags); |
| } |
| |
| void pm_qos_trace_dbg_dump(int pm_qos_class) |
| { |
| struct pm_qos_constraints *c; |
| struct pm_qos_request *req; |
| unsigned long flags; |
| struct list_head *l; |
| |
| if (pm_qos_class < PM_QOS_RESERVED |
| || pm_qos_class >= PM_QOS_NUM_CLASSES) |
| return; |
| |
| c = pm_qos_array[pm_qos_class]->constraints; |
| |
| spin_lock_irqsave(&pm_qos_lock, flags); |
| /* dump owner information*/ |
| list_for_each(l, &c->req_list) { |
| req = list_entry(l, struct pm_qos_request, list_node); |
| if ((req->node).prio != c->default_value) |
| pr_info("[PMQOS] = %d, %s, %d\n", |
| req->pm_qos_class, |
| req->owner, |
| req->node.prio); |
| } |
| spin_unlock_irqrestore(&pm_qos_lock, flags); |
| } |
| |
| static inline int pm_qos_get_value(struct pm_qos_constraints *c); |
| static int pm_qos_dbg_show_requests(struct seq_file *s, void *unused) |
| { |
| struct pm_qos_object *qos = (struct pm_qos_object *)s->private; |
| struct pm_qos_constraints *c; |
| struct pm_qos_request *req; |
| char *type; |
| unsigned long flags; |
| int tot_reqs = 0; |
| int active_reqs = 0; |
| struct list_head *l; |
| |
| if (IS_ERR_OR_NULL(qos)) { |
| pr_err("%s: bad qos param!\n", __func__); |
| return -EINVAL; |
| } |
| c = qos->constraints; |
| if (IS_ERR_OR_NULL(c)) { |
| pr_err("%s: Bad constraints on qos?\n", __func__); |
| return -EINVAL; |
| } |
| |
| /* Lock to ensure we have a snapshot */ |
| spin_lock_irqsave(&pm_qos_lock, flags); |
| if (plist_head_empty(&c->list)) { |
| seq_puts(s, "Empty!\n"); |
| goto out; |
| } |
| |
| switch (c->type) { |
| case PM_QOS_MIN: |
| type = "Minimum"; |
| break; |
| case PM_QOS_MAX: |
| type = "Maximum"; |
| break; |
| case PM_QOS_SUM: |
| type = "Sum"; |
| break; |
| default: |
| type = "Unknown"; |
| } |
| |
| plist_for_each_entry(req, &c->list, node) { |
| char *state = "Default"; |
| |
| if ((req->node).prio != c->default_value) { |
| active_reqs++; |
| state = "Active"; |
| } |
| tot_reqs++; |
| seq_printf(s, "%d: %d: %s\n", tot_reqs, |
| (req->node).prio, state); |
| } |
| |
| seq_printf(s, "Type=%s, Value=%d, Requests: active=%d / total=%d\n", |
| type, pm_qos_get_value(c), active_reqs, tot_reqs); |
| |
| /* dump req_list */ |
| list_for_each(l, &c->req_list) { |
| req = list_entry(l, struct pm_qos_request, list_node); |
| |
| seq_printf(s, "%s: %d\n", req->owner, req->node.prio); |
| } |
| |
| out: |
| spin_unlock_irqrestore(&pm_qos_lock, flags); |
| return 0; |
| } |
| |
| static int pm_qos_dbg_open(struct inode *inode, struct file *file) |
| { |
| return single_open(file, pm_qos_dbg_show_requests, |
| inode->i_private); |
| } |
| |
| static const struct file_operations pm_qos_debug_fops = { |
| .open = pm_qos_dbg_open, |
| .read = seq_read, |
| .llseek = seq_lseek, |
| .release = single_release, |
| }; |
| |
| void pm_qos_update_target_req_list(struct pm_qos_constraints *c, |
| struct pm_qos_request *req, enum pm_qos_req_action action) |
| { |
| unsigned long flags; |
| |
| spin_lock_irqsave(&pm_qos_lock, flags); |
| |
| switch (action) { |
| case PM_QOS_REMOVE_REQ: |
| list_del(&req->list_node); |
| break; |
| case PM_QOS_UPDATE_REQ: |
| /* |
| * to change the list, we atomically remove, reinit |
| * with new value and add, then see if the extremal |
| * changed |
| */ |
| list_del(&req->list_node); |
| case PM_QOS_ADD_REQ: |
| list_add(&req->list_node, &c->req_list); |
| break; |
| default: |
| /* no action */ |
| break; |
| } |
| |
| spin_unlock_irqrestore(&pm_qos_lock, flags); |
| } |
| |
| /** |
| * pm_qos_update_target - manages the constraints list and calls the notifiers |
| * if needed |
| * @c: constraints data struct |
| * @node: request to add to the list, to update or to remove |
| * @action: action to take on the constraints list |
| * @value: value of the request to add or update |
| * |
| * This function returns 1 if the aggregated constraint value has changed, 0 |
| * otherwise. |
| */ |
| int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node, |
| enum pm_qos_req_action action, int value) |
| { |
| unsigned long flags; |
| int prev_value, curr_value, new_value; |
| int ret; |
| |
| mutex_lock(&c->qos_lock); |
| spin_lock_irqsave(&pm_qos_lock, flags); |
| prev_value = pm_qos_get_value(c); |
| if (value == PM_QOS_DEFAULT_VALUE) |
| new_value = c->default_value; |
| else |
| new_value = value; |
| |
| switch (action) { |
| case PM_QOS_REMOVE_REQ: |
| plist_del(node, &c->list); |
| break; |
| case PM_QOS_UPDATE_REQ: |
| /* |
| * to change the list, we atomically remove, reinit |
| * with new value and add, then see if the extremal |
| * changed |
| */ |
| plist_del(node, &c->list); |
| case PM_QOS_ADD_REQ: |
| plist_node_init(node, new_value); |
| plist_add(node, &c->list); |
| break; |
| default: |
| /* no action */ |
| ; |
| } |
| |
| curr_value = pm_qos_get_value(c); |
| pm_qos_set_value(c, curr_value); |
| |
| spin_unlock_irqrestore(&pm_qos_lock, flags); |
| |
| trace_pm_qos_update_target(action, prev_value, curr_value); |
| if (prev_value != curr_value) { |
| ret = 1; |
| if (c->notifiers) |
| blocking_notifier_call_chain(c->notifiers, |
| (unsigned long)curr_value, |
| NULL); |
| } else { |
| ret = 0; |
| } |
| mutex_unlock(&c->qos_lock); |
| |
| return ret; |
| } |
| |
| /** |
| * pm_qos_flags_remove_req - Remove device PM QoS flags request. |
| * @pqf: Device PM QoS flags set to remove the request from. |
| * @req: Request to remove from the set. |
| */ |
| static void pm_qos_flags_remove_req(struct pm_qos_flags *pqf, |
| struct pm_qos_flags_request *req) |
| { |
| s32 val = 0; |
| |
| list_del(&req->node); |
| list_for_each_entry(req, &pqf->list, node) |
| val |= req->flags; |
| |
| pqf->effective_flags = val; |
| } |
| |
| /** |
| * pm_qos_update_flags - Update a set of PM QoS flags. |
| * @pqf: Set of flags to update. |
| * @req: Request to add to the set, to modify, or to remove from the set. |
| * @action: Action to take on the set. |
| * @val: Value of the request to add or modify. |
| * |
| * Update the given set of PM QoS flags and call notifiers if the aggregate |
| * value has changed. Returns 1 if the aggregate constraint value has changed, |
| * 0 otherwise. |
| */ |
| bool pm_qos_update_flags(struct pm_qos_flags *pqf, |
| struct pm_qos_flags_request *req, |
| enum pm_qos_req_action action, s32 val) |
| { |
| unsigned long irqflags; |
| s32 prev_value, curr_value; |
| |
| spin_lock_irqsave(&pm_qos_lock, irqflags); |
| |
| prev_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags; |
| |
| switch (action) { |
| case PM_QOS_REMOVE_REQ: |
| pm_qos_flags_remove_req(pqf, req); |
| break; |
| case PM_QOS_UPDATE_REQ: |
| pm_qos_flags_remove_req(pqf, req); |
| case PM_QOS_ADD_REQ: |
| req->flags = val; |
| INIT_LIST_HEAD(&req->node); |
| list_add_tail(&req->node, &pqf->list); |
| pqf->effective_flags |= val; |
| break; |
| default: |
| /* no action */ |
| ; |
| } |
| |
| curr_value = list_empty(&pqf->list) ? 0 : pqf->effective_flags; |
| |
| spin_unlock_irqrestore(&pm_qos_lock, irqflags); |
| |
| trace_pm_qos_update_flags(action, prev_value, curr_value); |
| return prev_value != curr_value; |
| } |
| |
| /** |
| * pm_qos_request - returns current system wide qos expectation |
| * @pm_qos_class: identification of which qos value is requested |
| * |
| * This function returns the current target value. |
| */ |
| int pm_qos_request(int pm_qos_class) |
| { |
| return pm_qos_read_value(pm_qos_array[pm_qos_class]->constraints); |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_request); |
| |
| int pm_qos_request_active(struct pm_qos_request *req) |
| { |
| return req->pm_qos_class != 0; |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_request_active); |
| |
| static void __pm_qos_update_request(struct pm_qos_request *req, |
| s32 new_value) |
| { |
| trace_pm_qos_update_request(req->pm_qos_class, new_value, req->owner); |
| |
| if (new_value != req->node.prio) { |
| pm_qos_update_target( |
| pm_qos_array[req->pm_qos_class]->constraints, |
| &req->node, PM_QOS_UPDATE_REQ, new_value); |
| pm_qos_update_target_req_list( |
| pm_qos_array[req->pm_qos_class]->constraints, |
| req, PM_QOS_UPDATE_REQ); |
| } |
| } |
| |
| /** |
| * pm_qos_work_fn - the timeout handler of pm_qos_update_request_timeout |
| * @work: work struct for the delayed work (timeout) |
| * |
| * This cancels the timeout request by falling back to the default at timeout. |
| */ |
| static void pm_qos_work_fn(struct work_struct *work) |
| { |
| struct pm_qos_request *req = container_of(to_delayed_work(work), |
| struct pm_qos_request, |
| work); |
| |
| __pm_qos_update_request(req, PM_QOS_DEFAULT_VALUE); |
| } |
| |
| /** |
| * pm_qos_add_request - inserts new qos request into the list |
| * @req: pointer to a preallocated handle |
| * @pm_qos_class: identifies which list of qos request to use |
| * @value: defines the qos request |
| * |
| * This function inserts a new entry in the pm_qos_class list of requested qos |
| * performance characteristics. It recomputes the aggregate QoS expectations |
| * for the pm_qos_class of parameters and initializes the pm_qos_request |
| * handle. Caller needs to save this handle for later use in updates and |
| * removal. |
| */ |
| |
| void pm_qos_add_request(struct pm_qos_request *req, |
| int pm_qos_class, s32 value) |
| { |
| char owner[20]; |
| if (!req) /*guard against callers passing in null */ |
| return; |
| |
| snprintf(owner, sizeof(owner) - 1, "%pf", __builtin_return_address(0)); |
| |
| if (pm_qos_request_active(req)) { |
| WARN(1, KERN_ERR "pm_qos_add_request() called for already added request\n"); |
| return; |
| } |
| |
| /* name of pm_qos reqester */ |
| strncpy(req->owner, owner, sizeof(req->owner) - 1); |
| |
| req->pm_qos_class = pm_qos_class; |
| INIT_DELAYED_WORK(&req->work, pm_qos_work_fn); |
| trace_pm_qos_add_request(pm_qos_class, value, req->owner); |
| pm_qos_update_target(pm_qos_array[pm_qos_class]->constraints, |
| &req->node, PM_QOS_ADD_REQ, value); |
| pm_qos_update_target_req_list(pm_qos_array[pm_qos_class]->constraints, |
| req, PM_QOS_ADD_REQ); |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_add_request); |
| |
| /** |
| * pm_qos_update_request - modifies an existing qos request |
| * @req : handle to list element holding a pm_qos request to use |
| * @value: defines the qos request |
| * |
| * Updates an existing qos request for the pm_qos_class of parameters along |
| * with updating the target pm_qos_class value. |
| * |
| * Attempts are made to make this code callable on hot code paths. |
| */ |
| void pm_qos_update_request(struct pm_qos_request *req, |
| s32 new_value) |
| { |
| if (!req) /*guard against callers passing in null */ |
| return; |
| |
| if (!pm_qos_request_active(req)) { |
| WARN(1, KERN_ERR "pm_qos_update_request() called for unknown object\n"); |
| return; |
| } |
| |
| cancel_delayed_work_sync(&req->work); |
| __pm_qos_update_request(req, new_value); |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_update_request); |
| |
| /** |
| * pm_qos_update_request_timeout - modifies an existing qos request temporarily. |
| * @req : handle to list element holding a pm_qos request to use |
| * @new_value: defines the temporal qos request |
| * @timeout_us: the effective duration of this qos request in usecs. |
| * |
| * After timeout_us, this qos request is cancelled automatically. |
| */ |
| void pm_qos_update_request_timeout(struct pm_qos_request *req, s32 new_value, |
| unsigned long timeout_us) |
| { |
| if (!req) |
| return; |
| if (WARN(!pm_qos_request_active(req), |
| "%s called for unknown object.", __func__)) |
| return; |
| |
| cancel_delayed_work_sync(&req->work); |
| |
| trace_pm_qos_update_request_timeout(req->pm_qos_class, |
| new_value, timeout_us); |
| if (new_value != req->node.prio) { |
| pm_qos_update_target( |
| pm_qos_array[req->pm_qos_class]->constraints, |
| &req->node, PM_QOS_UPDATE_REQ, new_value); |
| pm_qos_update_target_req_list( |
| pm_qos_array[req->pm_qos_class]->constraints, |
| req, PM_QOS_UPDATE_REQ); |
| } |
| |
| schedule_delayed_work(&req->work, usecs_to_jiffies(timeout_us)); |
| } |
| |
| /** |
| * pm_qos_remove_request - modifies an existing qos request |
| * @req: handle to request list element |
| * |
| * Will remove pm qos request from the list of constraints and |
| * recompute the current target value for the pm_qos_class. Call this |
| * on slow code paths. |
| */ |
| void pm_qos_remove_request(struct pm_qos_request *req) |
| { |
| if (!req) /*guard against callers passing in null */ |
| return; |
| /* silent return to keep pcm code cleaner */ |
| |
| if (!pm_qos_request_active(req)) { |
| WARN(1, KERN_ERR "pm_qos_remove_request() called for unknown object\n"); |
| return; |
| } |
| |
| cancel_delayed_work_sync(&req->work); |
| |
| trace_pm_qos_remove_request(req->pm_qos_class, PM_QOS_DEFAULT_VALUE, |
| req->owner); |
| pm_qos_update_target(pm_qos_array[req->pm_qos_class]->constraints, |
| &req->node, PM_QOS_REMOVE_REQ, |
| PM_QOS_DEFAULT_VALUE); |
| pm_qos_update_target_req_list( |
| pm_qos_array[req->pm_qos_class]->constraints, req, |
| PM_QOS_REMOVE_REQ); |
| memset(req, 0, sizeof(*req)); |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_remove_request); |
| |
| /** |
| * pm_qos_add_notifier - sets notification entry for changes to target value |
| * @pm_qos_class: identifies which qos target changes should be notified. |
| * @notifier: notifier block managed by caller. |
| * |
| * will register the notifier into a notification chain that gets called |
| * upon changes to the pm_qos_class target value. |
| */ |
| int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier) |
| { |
| int retval; |
| |
| retval = blocking_notifier_chain_register( |
| pm_qos_array[pm_qos_class]->constraints->notifiers, |
| notifier); |
| |
| return retval; |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_add_notifier); |
| |
| /** |
| * pm_qos_remove_notifier - deletes notification entry from chain. |
| * @pm_qos_class: identifies which qos target changes are notified. |
| * @notifier: notifier block to be removed. |
| * |
| * will remove the notifier from the notification chain that gets called |
| * upon changes to the pm_qos_class target value. |
| */ |
| int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier) |
| { |
| int retval; |
| |
| retval = blocking_notifier_chain_unregister( |
| pm_qos_array[pm_qos_class]->constraints->notifiers, |
| notifier); |
| |
| return retval; |
| } |
| EXPORT_SYMBOL_GPL(pm_qos_remove_notifier); |
| |
| /* User space interface to PM QoS classes via misc devices */ |
| static int register_pm_qos_misc(struct pm_qos_object *qos, struct dentry *d) |
| { |
| qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR; |
| qos->pm_qos_power_miscdev.name = qos->name; |
| qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops; |
| |
| if (d) { |
| (void)debugfs_create_file(qos->name, S_IRUGO, d, |
| (void *)qos, &pm_qos_debug_fops); |
| } |
| |
| return misc_register(&qos->pm_qos_power_miscdev); |
| } |
| |
| /* User space interface to PM QoS classes via misc devices */ |
| static int register_pm_qos_debug(struct pm_qos_object *qos, struct dentry *d) |
| { |
| qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR; |
| qos->pm_qos_power_miscdev.name = qos->name; |
| qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops; |
| |
| if (d) { |
| (void)debugfs_create_file(qos->name, 0444, d, |
| (void *)qos, &pm_qos_debug_fops); |
| } |
| |
| return 0; |
| } |
| |
| static int find_pm_qos_object_by_minor(int minor) |
| { |
| int pm_qos_class; |
| |
| for (pm_qos_class = PM_QOS_CPU_DMA_LATENCY; |
| pm_qos_class < PM_QOS_NUM_CLASSES; pm_qos_class++) { |
| if (minor == |
| pm_qos_array[pm_qos_class]->pm_qos_power_miscdev.minor) |
| return pm_qos_class; |
| } |
| return -1; |
| } |
| |
| static int pm_qos_power_open(struct inode *inode, struct file *filp) |
| { |
| long pm_qos_class; |
| |
| pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); |
| if (pm_qos_class >= PM_QOS_CPU_DMA_LATENCY) { |
| struct pm_qos_request *req = kzalloc(sizeof(*req), GFP_KERNEL); |
| if (!req) |
| return -ENOMEM; |
| |
| pm_qos_add_request(req, pm_qos_class, PM_QOS_DEFAULT_VALUE); |
| filp->private_data = req; |
| |
| return 0; |
| } |
| return -EPERM; |
| } |
| |
| static int pm_qos_power_release(struct inode *inode, struct file *filp) |
| { |
| struct pm_qos_request *req; |
| |
| req = filp->private_data; |
| pm_qos_remove_request(req); |
| kfree(req); |
| |
| return 0; |
| } |
| |
| |
| static ssize_t pm_qos_power_read(struct file *filp, char __user *buf, |
| size_t count, loff_t *f_pos) |
| { |
| s32 value; |
| unsigned long flags; |
| struct pm_qos_request *req = filp->private_data; |
| |
| if (!req) |
| return -EINVAL; |
| if (!pm_qos_request_active(req)) |
| return -EINVAL; |
| |
| spin_lock_irqsave(&pm_qos_lock, flags); |
| value = pm_qos_get_value(pm_qos_array[req->pm_qos_class]->constraints); |
| spin_unlock_irqrestore(&pm_qos_lock, flags); |
| |
| return simple_read_from_buffer(buf, count, f_pos, &value, sizeof(s32)); |
| } |
| |
| static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, |
| size_t count, loff_t *f_pos) |
| { |
| s32 value; |
| struct pm_qos_request *req; |
| |
| if (count == sizeof(s32)) { |
| if (copy_from_user(&value, buf, sizeof(s32))) |
| return -EFAULT; |
| } else { |
| int ret; |
| |
| ret = kstrtos32_from_user(buf, count, 16, &value); |
| if (ret) |
| return ret; |
| } |
| |
| req = filp->private_data; |
| pm_qos_update_request(req, value); |
| |
| return count; |
| } |
| |
| |
| static int __init pm_qos_power_init(void) |
| { |
| int ret = 0; |
| int i; |
| struct dentry *d; |
| |
| BUILD_BUG_ON(ARRAY_SIZE(pm_qos_array) != PM_QOS_NUM_CLASSES); |
| |
| d = debugfs_create_dir("pm_qos", NULL); |
| if (IS_ERR_OR_NULL(d)) |
| d = NULL; |
| |
| for (i = PM_QOS_CPU_DMA_LATENCY; i < PM_QOS_NUM_CLASSES; i++) { |
| if (i > PM_QOS_MEMORY_BANDWIDTH) |
| ret = register_pm_qos_debug(pm_qos_array[i], d); |
| else |
| ret = register_pm_qos_misc(pm_qos_array[i], d); |
| if (ret < 0) { |
| printk(KERN_ERR "pm_qos_param: %s setup failed\n", |
| pm_qos_array[i]->name); |
| return ret; |
| } |
| } |
| |
| return ret; |
| } |
| |
| late_initcall(pm_qos_power_init); |