18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * linux/include/linux/cpufreq.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2001 Russell King
68c2ecf20Sopenharmony_ci *           (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#ifndef _LINUX_CPUFREQ_H
98c2ecf20Sopenharmony_ci#define _LINUX_CPUFREQ_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/clk.h>
128c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
138c2ecf20Sopenharmony_ci#include <linux/completion.h>
148c2ecf20Sopenharmony_ci#include <linux/kobject.h>
158c2ecf20Sopenharmony_ci#include <linux/notifier.h>
168c2ecf20Sopenharmony_ci#include <linux/pm_qos.h>
178c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
188c2ecf20Sopenharmony_ci#include <linux/sysfs.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/*********************************************************************
218c2ecf20Sopenharmony_ci *                        CPUFREQ INTERFACE                          *
228c2ecf20Sopenharmony_ci *********************************************************************/
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * Frequency values here are CPU kHz
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * Maximum transition latency is in nanoseconds - if it's unknown,
278c2ecf20Sopenharmony_ci * CPUFREQ_ETERNAL shall be used.
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define CPUFREQ_ETERNAL			(-1)
318c2ecf20Sopenharmony_ci#define CPUFREQ_NAME_LEN		16
328c2ecf20Sopenharmony_ci/* Print length for names. Extra 1 space for accommodating '\n' in prints */
338c2ecf20Sopenharmony_ci#define CPUFREQ_NAME_PLEN		(CPUFREQ_NAME_LEN + 1)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct cpufreq_governor;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cienum cpufreq_table_sorting {
388c2ecf20Sopenharmony_ci	CPUFREQ_TABLE_UNSORTED,
398c2ecf20Sopenharmony_ci	CPUFREQ_TABLE_SORTED_ASCENDING,
408c2ecf20Sopenharmony_ci	CPUFREQ_TABLE_SORTED_DESCENDING
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct cpufreq_cpuinfo {
448c2ecf20Sopenharmony_ci	unsigned int		max_freq;
458c2ecf20Sopenharmony_ci	unsigned int		min_freq;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	/* in 10^(-9) s = nanoseconds */
488c2ecf20Sopenharmony_ci	unsigned int		transition_latency;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct cpufreq_policy {
528c2ecf20Sopenharmony_ci	/* CPUs sharing clock, require sw coordination */
538c2ecf20Sopenharmony_ci	cpumask_var_t		cpus;	/* Online CPUs only */
548c2ecf20Sopenharmony_ci	cpumask_var_t		related_cpus; /* Online + Offline CPUs */
558c2ecf20Sopenharmony_ci	cpumask_var_t		real_cpus; /* Related and present */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	unsigned int		shared_type; /* ACPI: ANY or ALL affected CPUs
588c2ecf20Sopenharmony_ci						should set cpufreq */
598c2ecf20Sopenharmony_ci	unsigned int		cpu;    /* cpu managing this policy, must be online */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	struct clk		*clk;
628c2ecf20Sopenharmony_ci	struct cpufreq_cpuinfo	cpuinfo;/* see above */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	unsigned int		min;    /* in kHz */
658c2ecf20Sopenharmony_ci	unsigned int		max;    /* in kHz */
668c2ecf20Sopenharmony_ci	unsigned int		cur;    /* in kHz, only needed if cpufreq
678c2ecf20Sopenharmony_ci					 * governors are used */
688c2ecf20Sopenharmony_ci	unsigned int		restore_freq; /* = policy->cur before transition */
698c2ecf20Sopenharmony_ci	unsigned int		suspend_freq; /* freq to set during suspend */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	unsigned int		policy; /* see above */
728c2ecf20Sopenharmony_ci	unsigned int		last_policy; /* policy before unplug */
738c2ecf20Sopenharmony_ci	struct cpufreq_governor	*governor; /* see below */
748c2ecf20Sopenharmony_ci	void			*governor_data;
758c2ecf20Sopenharmony_ci	char			last_governor[CPUFREQ_NAME_LEN]; /* last governor used */
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	struct work_struct	update; /* if update_policy() needs to be
788c2ecf20Sopenharmony_ci					 * called, but you're in IRQ context */
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	struct freq_constraints	constraints;
818c2ecf20Sopenharmony_ci	struct freq_qos_request	*min_freq_req;
828c2ecf20Sopenharmony_ci	struct freq_qos_request	*max_freq_req;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table	*freq_table;
858c2ecf20Sopenharmony_ci	enum cpufreq_table_sorting freq_table_sorted;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	struct list_head        policy_list;
888c2ecf20Sopenharmony_ci	struct kobject		kobj;
898c2ecf20Sopenharmony_ci	struct completion	kobj_unregister;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	/*
928c2ecf20Sopenharmony_ci	 * The rules for this semaphore:
938c2ecf20Sopenharmony_ci	 * - Any routine that wants to read from the policy structure will
948c2ecf20Sopenharmony_ci	 *   do a down_read on this semaphore.
958c2ecf20Sopenharmony_ci	 * - Any routine that will write to the policy structure and/or may take away
968c2ecf20Sopenharmony_ci	 *   the policy altogether (eg. CPU hotplug), will hold this lock in write
978c2ecf20Sopenharmony_ci	 *   mode before doing so.
988c2ecf20Sopenharmony_ci	 */
998c2ecf20Sopenharmony_ci	struct rw_semaphore	rwsem;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/*
1028c2ecf20Sopenharmony_ci	 * Fast switch flags:
1038c2ecf20Sopenharmony_ci	 * - fast_switch_possible should be set by the driver if it can
1048c2ecf20Sopenharmony_ci	 *   guarantee that frequency can be changed on any CPU sharing the
1058c2ecf20Sopenharmony_ci	 *   policy and that the change will affect all of the policy CPUs then.
1068c2ecf20Sopenharmony_ci	 * - fast_switch_enabled is to be set by governors that support fast
1078c2ecf20Sopenharmony_ci	 *   frequency switching with the help of cpufreq_enable_fast_switch().
1088c2ecf20Sopenharmony_ci	 */
1098c2ecf20Sopenharmony_ci	bool			fast_switch_possible;
1108c2ecf20Sopenharmony_ci	bool			fast_switch_enabled;
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	/*
1138c2ecf20Sopenharmony_ci	 * Set if the CPUFREQ_GOV_STRICT_TARGET flag is set for the current
1148c2ecf20Sopenharmony_ci	 * governor.
1158c2ecf20Sopenharmony_ci	 */
1168c2ecf20Sopenharmony_ci	bool			strict_target;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	/*
1198c2ecf20Sopenharmony_ci	 * Preferred average time interval between consecutive invocations of
1208c2ecf20Sopenharmony_ci	 * the driver to set the frequency for this policy.  To be set by the
1218c2ecf20Sopenharmony_ci	 * scaling driver (0, which is the default, means no preference).
1228c2ecf20Sopenharmony_ci	 */
1238c2ecf20Sopenharmony_ci	unsigned int		transition_delay_us;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/*
1268c2ecf20Sopenharmony_ci	 * Remote DVFS flag (Not added to the driver structure as we don't want
1278c2ecf20Sopenharmony_ci	 * to access another structure from scheduler hotpath).
1288c2ecf20Sopenharmony_ci	 *
1298c2ecf20Sopenharmony_ci	 * Should be set if CPUs can do DVFS on behalf of other CPUs from
1308c2ecf20Sopenharmony_ci	 * different cpufreq policies.
1318c2ecf20Sopenharmony_ci	 */
1328c2ecf20Sopenharmony_ci	bool			dvfs_possible_from_any_cpu;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	 /* Cached frequency lookup from cpufreq_driver_resolve_freq. */
1358c2ecf20Sopenharmony_ci	unsigned int cached_target_freq;
1368c2ecf20Sopenharmony_ci	unsigned int cached_resolved_idx;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	/* Synchronization for frequency transitions */
1398c2ecf20Sopenharmony_ci	bool			transition_ongoing; /* Tracks transition status */
1408c2ecf20Sopenharmony_ci	spinlock_t		transition_lock;
1418c2ecf20Sopenharmony_ci	wait_queue_head_t	transition_wait;
1428c2ecf20Sopenharmony_ci	struct task_struct	*transition_task; /* Task which is doing the transition */
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/* cpufreq-stats */
1458c2ecf20Sopenharmony_ci	struct cpufreq_stats	*stats;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	/* For cpufreq driver's internal use */
1488c2ecf20Sopenharmony_ci	void			*driver_data;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	/* Pointer to the cooling device if used for thermal mitigation */
1518c2ecf20Sopenharmony_ci	struct thermal_cooling_device *cdev;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	struct notifier_block nb_min;
1548c2ecf20Sopenharmony_ci	struct notifier_block nb_max;
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/*
1588c2ecf20Sopenharmony_ci * Used for passing new cpufreq policy data to the cpufreq driver's ->verify()
1598c2ecf20Sopenharmony_ci * callback for sanitization.  That callback is only expected to modify the min
1608c2ecf20Sopenharmony_ci * and max values, if necessary, and specifically it must not update the
1618c2ecf20Sopenharmony_ci * frequency table.
1628c2ecf20Sopenharmony_ci */
1638c2ecf20Sopenharmony_cistruct cpufreq_policy_data {
1648c2ecf20Sopenharmony_ci	struct cpufreq_cpuinfo		cpuinfo;
1658c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table	*freq_table;
1668c2ecf20Sopenharmony_ci	unsigned int			cpu;
1678c2ecf20Sopenharmony_ci	unsigned int			min;    /* in kHz */
1688c2ecf20Sopenharmony_ci	unsigned int			max;    /* in kHz */
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistruct cpufreq_freqs {
1728c2ecf20Sopenharmony_ci	struct cpufreq_policy *policy;
1738c2ecf20Sopenharmony_ci	unsigned int old;
1748c2ecf20Sopenharmony_ci	unsigned int new;
1758c2ecf20Sopenharmony_ci	u8 flags;		/* flags of cpufreq_driver, see below. */
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/* Only for ACPI */
1798c2ecf20Sopenharmony_ci#define CPUFREQ_SHARED_TYPE_NONE (0) /* None */
1808c2ecf20Sopenharmony_ci#define CPUFREQ_SHARED_TYPE_HW	 (1) /* HW does needed coordination */
1818c2ecf20Sopenharmony_ci#define CPUFREQ_SHARED_TYPE_ALL	 (2) /* All dependent CPUs should set freq */
1828c2ecf20Sopenharmony_ci#define CPUFREQ_SHARED_TYPE_ANY	 (3) /* Freq can be set from any dependent CPU*/
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_FREQ
1858c2ecf20Sopenharmony_cistruct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu);
1868c2ecf20Sopenharmony_cistruct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
1878c2ecf20Sopenharmony_civoid cpufreq_cpu_put(struct cpufreq_policy *policy);
1888c2ecf20Sopenharmony_ci#else
1898c2ecf20Sopenharmony_cistatic inline struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
1908c2ecf20Sopenharmony_ci{
1918c2ecf20Sopenharmony_ci	return NULL;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_cistatic inline struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
1948c2ecf20Sopenharmony_ci{
1958c2ecf20Sopenharmony_ci	return NULL;
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_cistatic inline void cpufreq_cpu_put(struct cpufreq_policy *policy) { }
1988c2ecf20Sopenharmony_ci#endif
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistatic inline bool policy_is_inactive(struct cpufreq_policy *policy)
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	return cpumask_empty(policy->cpus);
2038c2ecf20Sopenharmony_ci}
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_cistatic inline bool policy_is_shared(struct cpufreq_policy *policy)
2068c2ecf20Sopenharmony_ci{
2078c2ecf20Sopenharmony_ci	return cpumask_weight(policy->cpus) > 1;
2088c2ecf20Sopenharmony_ci}
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_FREQ
2118c2ecf20Sopenharmony_ciunsigned int cpufreq_get(unsigned int cpu);
2128c2ecf20Sopenharmony_ciunsigned int cpufreq_quick_get(unsigned int cpu);
2138c2ecf20Sopenharmony_ciunsigned int cpufreq_quick_get_max(unsigned int cpu);
2148c2ecf20Sopenharmony_ciunsigned int cpufreq_get_hw_max_freq(unsigned int cpu);
2158c2ecf20Sopenharmony_civoid disable_cpufreq(void);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ciu64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistruct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu);
2208c2ecf20Sopenharmony_civoid cpufreq_cpu_release(struct cpufreq_policy *policy);
2218c2ecf20Sopenharmony_ciint cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);
2228c2ecf20Sopenharmony_civoid refresh_frequency_limits(struct cpufreq_policy *policy);
2238c2ecf20Sopenharmony_civoid cpufreq_update_policy(unsigned int cpu);
2248c2ecf20Sopenharmony_civoid cpufreq_update_limits(unsigned int cpu);
2258c2ecf20Sopenharmony_cibool have_governor_per_policy(void);
2268c2ecf20Sopenharmony_cibool cpufreq_supports_freq_invariance(void);
2278c2ecf20Sopenharmony_cistruct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
2288c2ecf20Sopenharmony_civoid cpufreq_enable_fast_switch(struct cpufreq_policy *policy);
2298c2ecf20Sopenharmony_civoid cpufreq_disable_fast_switch(struct cpufreq_policy *policy);
2308c2ecf20Sopenharmony_ci#else
2318c2ecf20Sopenharmony_cistatic inline unsigned int cpufreq_get(unsigned int cpu)
2328c2ecf20Sopenharmony_ci{
2338c2ecf20Sopenharmony_ci	return 0;
2348c2ecf20Sopenharmony_ci}
2358c2ecf20Sopenharmony_cistatic inline unsigned int cpufreq_quick_get(unsigned int cpu)
2368c2ecf20Sopenharmony_ci{
2378c2ecf20Sopenharmony_ci	return 0;
2388c2ecf20Sopenharmony_ci}
2398c2ecf20Sopenharmony_cistatic inline unsigned int cpufreq_quick_get_max(unsigned int cpu)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	return 0;
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_cistatic inline unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	return 0;
2468c2ecf20Sopenharmony_ci}
2478c2ecf20Sopenharmony_cistatic inline bool cpufreq_supports_freq_invariance(void)
2488c2ecf20Sopenharmony_ci{
2498c2ecf20Sopenharmony_ci	return false;
2508c2ecf20Sopenharmony_ci}
2518c2ecf20Sopenharmony_cistatic inline void disable_cpufreq(void) { }
2528c2ecf20Sopenharmony_ci#endif
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_FREQ_STAT
2558c2ecf20Sopenharmony_civoid cpufreq_stats_create_table(struct cpufreq_policy *policy);
2568c2ecf20Sopenharmony_civoid cpufreq_stats_free_table(struct cpufreq_policy *policy);
2578c2ecf20Sopenharmony_civoid cpufreq_stats_record_transition(struct cpufreq_policy *policy,
2588c2ecf20Sopenharmony_ci				     unsigned int new_freq);
2598c2ecf20Sopenharmony_ci#else
2608c2ecf20Sopenharmony_cistatic inline void cpufreq_stats_create_table(struct cpufreq_policy *policy) { }
2618c2ecf20Sopenharmony_cistatic inline void cpufreq_stats_free_table(struct cpufreq_policy *policy) { }
2628c2ecf20Sopenharmony_cistatic inline void cpufreq_stats_record_transition(struct cpufreq_policy *policy,
2638c2ecf20Sopenharmony_ci						   unsigned int new_freq) { }
2648c2ecf20Sopenharmony_ci#endif /* CONFIG_CPU_FREQ_STAT */
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci/*********************************************************************
2678c2ecf20Sopenharmony_ci *                      CPUFREQ DRIVER INTERFACE                     *
2688c2ecf20Sopenharmony_ci *********************************************************************/
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci#define CPUFREQ_RELATION_L 0  /* lowest frequency at or above target */
2718c2ecf20Sopenharmony_ci#define CPUFREQ_RELATION_H 1  /* highest frequency below or at target */
2728c2ecf20Sopenharmony_ci#define CPUFREQ_RELATION_C 2  /* closest frequency to target */
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cistruct freq_attr {
2758c2ecf20Sopenharmony_ci	struct attribute attr;
2768c2ecf20Sopenharmony_ci	ssize_t (*show)(struct cpufreq_policy *, char *);
2778c2ecf20Sopenharmony_ci	ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
2788c2ecf20Sopenharmony_ci};
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci#define cpufreq_freq_attr_ro(_name)		\
2818c2ecf20Sopenharmony_cistatic struct freq_attr _name =			\
2828c2ecf20Sopenharmony_ci__ATTR(_name, 0444, show_##_name, NULL)
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci#define cpufreq_freq_attr_ro_perm(_name, _perm)	\
2858c2ecf20Sopenharmony_cistatic struct freq_attr _name =			\
2868c2ecf20Sopenharmony_ci__ATTR(_name, _perm, show_##_name, NULL)
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci#define cpufreq_freq_attr_rw(_name)		\
2898c2ecf20Sopenharmony_cistatic struct freq_attr _name =			\
2908c2ecf20Sopenharmony_ci__ATTR(_name, 0644, show_##_name, store_##_name)
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#define cpufreq_freq_attr_wo(_name)		\
2938c2ecf20Sopenharmony_cistatic struct freq_attr _name =			\
2948c2ecf20Sopenharmony_ci__ATTR(_name, 0200, NULL, store_##_name)
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci#define define_one_global_ro(_name)		\
2978c2ecf20Sopenharmony_cistatic struct kobj_attribute _name =		\
2988c2ecf20Sopenharmony_ci__ATTR(_name, 0444, show_##_name, NULL)
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci#define define_one_global_rw(_name)		\
3018c2ecf20Sopenharmony_cistatic struct kobj_attribute _name =		\
3028c2ecf20Sopenharmony_ci__ATTR(_name, 0644, show_##_name, store_##_name)
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistruct cpufreq_driver {
3068c2ecf20Sopenharmony_ci	char		name[CPUFREQ_NAME_LEN];
3078c2ecf20Sopenharmony_ci	u16		flags;
3088c2ecf20Sopenharmony_ci	void		*driver_data;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	/* needed by all drivers */
3118c2ecf20Sopenharmony_ci	int		(*init)(struct cpufreq_policy *policy);
3128c2ecf20Sopenharmony_ci	int		(*verify)(struct cpufreq_policy_data *policy);
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	/* define one out of two */
3158c2ecf20Sopenharmony_ci	int		(*setpolicy)(struct cpufreq_policy *policy);
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	/*
3188c2ecf20Sopenharmony_ci	 * On failure, should always restore frequency to policy->restore_freq
3198c2ecf20Sopenharmony_ci	 * (i.e. old freq).
3208c2ecf20Sopenharmony_ci	 */
3218c2ecf20Sopenharmony_ci	int		(*target)(struct cpufreq_policy *policy,
3228c2ecf20Sopenharmony_ci				  unsigned int target_freq,
3238c2ecf20Sopenharmony_ci				  unsigned int relation);	/* Deprecated */
3248c2ecf20Sopenharmony_ci	int		(*target_index)(struct cpufreq_policy *policy,
3258c2ecf20Sopenharmony_ci					unsigned int index);
3268c2ecf20Sopenharmony_ci	unsigned int	(*fast_switch)(struct cpufreq_policy *policy,
3278c2ecf20Sopenharmony_ci				       unsigned int target_freq);
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	/*
3308c2ecf20Sopenharmony_ci	 * Caches and returns the lowest driver-supported frequency greater than
3318c2ecf20Sopenharmony_ci	 * or equal to the target frequency, subject to any driver limitations.
3328c2ecf20Sopenharmony_ci	 * Does not set the frequency. Only to be implemented for drivers with
3338c2ecf20Sopenharmony_ci	 * target().
3348c2ecf20Sopenharmony_ci	 */
3358c2ecf20Sopenharmony_ci	unsigned int	(*resolve_freq)(struct cpufreq_policy *policy,
3368c2ecf20Sopenharmony_ci					unsigned int target_freq);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	/*
3398c2ecf20Sopenharmony_ci	 * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION
3408c2ecf20Sopenharmony_ci	 * unset.
3418c2ecf20Sopenharmony_ci	 *
3428c2ecf20Sopenharmony_ci	 * get_intermediate should return a stable intermediate frequency
3438c2ecf20Sopenharmony_ci	 * platform wants to switch to and target_intermediate() should set CPU
3448c2ecf20Sopenharmony_ci	 * to that frequency, before jumping to the frequency corresponding
3458c2ecf20Sopenharmony_ci	 * to 'index'. Core will take care of sending notifications and driver
3468c2ecf20Sopenharmony_ci	 * doesn't have to handle them in target_intermediate() or
3478c2ecf20Sopenharmony_ci	 * target_index().
3488c2ecf20Sopenharmony_ci	 *
3498c2ecf20Sopenharmony_ci	 * Drivers can return '0' from get_intermediate() in case they don't
3508c2ecf20Sopenharmony_ci	 * wish to switch to intermediate frequency for some target frequency.
3518c2ecf20Sopenharmony_ci	 * In that case core will directly call ->target_index().
3528c2ecf20Sopenharmony_ci	 */
3538c2ecf20Sopenharmony_ci	unsigned int	(*get_intermediate)(struct cpufreq_policy *policy,
3548c2ecf20Sopenharmony_ci					    unsigned int index);
3558c2ecf20Sopenharmony_ci	int		(*target_intermediate)(struct cpufreq_policy *policy,
3568c2ecf20Sopenharmony_ci					       unsigned int index);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	/* should be defined, if possible */
3598c2ecf20Sopenharmony_ci	unsigned int	(*get)(unsigned int cpu);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	/* Called to update policy limits on firmware notifications. */
3628c2ecf20Sopenharmony_ci	void		(*update_limits)(unsigned int cpu);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	/* optional */
3658c2ecf20Sopenharmony_ci	int		(*bios_limit)(int cpu, unsigned int *limit);
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	int		(*online)(struct cpufreq_policy *policy);
3688c2ecf20Sopenharmony_ci	int		(*offline)(struct cpufreq_policy *policy);
3698c2ecf20Sopenharmony_ci	int		(*exit)(struct cpufreq_policy *policy);
3708c2ecf20Sopenharmony_ci	void		(*stop_cpu)(struct cpufreq_policy *policy);
3718c2ecf20Sopenharmony_ci	int		(*suspend)(struct cpufreq_policy *policy);
3728c2ecf20Sopenharmony_ci	int		(*resume)(struct cpufreq_policy *policy);
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	/* Will be called after the driver is fully initialized */
3758c2ecf20Sopenharmony_ci	void		(*ready)(struct cpufreq_policy *policy);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	struct freq_attr **attr;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	/* platform specific boost support code */
3808c2ecf20Sopenharmony_ci	bool		boost_enabled;
3818c2ecf20Sopenharmony_ci	int		(*set_boost)(struct cpufreq_policy *policy, int state);
3828c2ecf20Sopenharmony_ci};
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci/* flags */
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci/* driver isn't removed even if all ->init() calls failed */
3878c2ecf20Sopenharmony_ci#define CPUFREQ_STICKY				BIT(0)
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/* loops_per_jiffy or other kernel "constants" aren't affected by frequency transitions */
3908c2ecf20Sopenharmony_ci#define CPUFREQ_CONST_LOOPS			BIT(1)
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci/* don't warn on suspend/resume speed mismatches */
3938c2ecf20Sopenharmony_ci#define CPUFREQ_PM_NO_WARN			BIT(2)
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci/*
3968c2ecf20Sopenharmony_ci * This should be set by platforms having multiple clock-domains, i.e.
3978c2ecf20Sopenharmony_ci * supporting multiple policies. With this sysfs directories of governor would
3988c2ecf20Sopenharmony_ci * be created in cpu/cpu<num>/cpufreq/ directory and so they can use the same
3998c2ecf20Sopenharmony_ci * governor with different tunables for different clusters.
4008c2ecf20Sopenharmony_ci */
4018c2ecf20Sopenharmony_ci#define CPUFREQ_HAVE_GOVERNOR_PER_POLICY	BIT(3)
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci/*
4048c2ecf20Sopenharmony_ci * Driver will do POSTCHANGE notifications from outside of their ->target()
4058c2ecf20Sopenharmony_ci * routine and so must set cpufreq_driver->flags with this flag, so that core
4068c2ecf20Sopenharmony_ci * can handle them specially.
4078c2ecf20Sopenharmony_ci */
4088c2ecf20Sopenharmony_ci#define CPUFREQ_ASYNC_NOTIFICATION		BIT(4)
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci/*
4118c2ecf20Sopenharmony_ci * Set by drivers which want cpufreq core to check if CPU is running at a
4128c2ecf20Sopenharmony_ci * frequency present in freq-table exposed by the driver. For these drivers if
4138c2ecf20Sopenharmony_ci * CPU is found running at an out of table freq, we will try to set it to a freq
4148c2ecf20Sopenharmony_ci * from the table. And if that fails, we will stop further boot process by
4158c2ecf20Sopenharmony_ci * issuing a BUG_ON().
4168c2ecf20Sopenharmony_ci */
4178c2ecf20Sopenharmony_ci#define CPUFREQ_NEED_INITIAL_FREQ_CHECK	BIT(5)
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/*
4208c2ecf20Sopenharmony_ci * Set by drivers to disallow use of governors with "dynamic_switching" flag
4218c2ecf20Sopenharmony_ci * set.
4228c2ecf20Sopenharmony_ci */
4238c2ecf20Sopenharmony_ci#define CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING	BIT(6)
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci/*
4268c2ecf20Sopenharmony_ci * Set by drivers that want the core to automatically register the cpufreq
4278c2ecf20Sopenharmony_ci * driver as a thermal cooling device.
4288c2ecf20Sopenharmony_ci */
4298c2ecf20Sopenharmony_ci#define CPUFREQ_IS_COOLING_DEV			BIT(7)
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/*
4328c2ecf20Sopenharmony_ci * Set by drivers that need to update internale upper and lower boundaries along
4338c2ecf20Sopenharmony_ci * with the target frequency and so the core and governors should also invoke
4348c2ecf20Sopenharmony_ci * the diver if the target frequency does not change, but the policy min or max
4358c2ecf20Sopenharmony_ci * may have changed.
4368c2ecf20Sopenharmony_ci */
4378c2ecf20Sopenharmony_ci#define CPUFREQ_NEED_UPDATE_LIMITS		BIT(8)
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ciint cpufreq_register_driver(struct cpufreq_driver *driver_data);
4408c2ecf20Sopenharmony_ciint cpufreq_unregister_driver(struct cpufreq_driver *driver_data);
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cibool cpufreq_driver_test_flags(u16 flags);
4438c2ecf20Sopenharmony_ciconst char *cpufreq_get_current_driver(void);
4448c2ecf20Sopenharmony_civoid *cpufreq_get_driver_data(void);
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cistatic inline int cpufreq_thermal_control_enabled(struct cpufreq_driver *drv)
4478c2ecf20Sopenharmony_ci{
4488c2ecf20Sopenharmony_ci	return IS_ENABLED(CONFIG_CPU_THERMAL) &&
4498c2ecf20Sopenharmony_ci		(drv->flags & CPUFREQ_IS_COOLING_DEV);
4508c2ecf20Sopenharmony_ci}
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_cistatic inline void cpufreq_verify_within_limits(struct cpufreq_policy_data *policy,
4538c2ecf20Sopenharmony_ci						unsigned int min,
4548c2ecf20Sopenharmony_ci						unsigned int max)
4558c2ecf20Sopenharmony_ci{
4568c2ecf20Sopenharmony_ci	if (policy->min < min)
4578c2ecf20Sopenharmony_ci		policy->min = min;
4588c2ecf20Sopenharmony_ci	if (policy->max < min)
4598c2ecf20Sopenharmony_ci		policy->max = min;
4608c2ecf20Sopenharmony_ci	if (policy->min > max)
4618c2ecf20Sopenharmony_ci		policy->min = max;
4628c2ecf20Sopenharmony_ci	if (policy->max > max)
4638c2ecf20Sopenharmony_ci		policy->max = max;
4648c2ecf20Sopenharmony_ci	if (policy->min > policy->max)
4658c2ecf20Sopenharmony_ci		policy->min = policy->max;
4668c2ecf20Sopenharmony_ci	return;
4678c2ecf20Sopenharmony_ci}
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_cistatic inline void
4708c2ecf20Sopenharmony_cicpufreq_verify_within_cpu_limits(struct cpufreq_policy_data *policy)
4718c2ecf20Sopenharmony_ci{
4728c2ecf20Sopenharmony_ci	cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
4738c2ecf20Sopenharmony_ci				     policy->cpuinfo.max_freq);
4748c2ecf20Sopenharmony_ci}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_FREQ
4778c2ecf20Sopenharmony_civoid cpufreq_suspend(void);
4788c2ecf20Sopenharmony_civoid cpufreq_resume(void);
4798c2ecf20Sopenharmony_ciint cpufreq_generic_suspend(struct cpufreq_policy *policy);
4808c2ecf20Sopenharmony_ci#else
4818c2ecf20Sopenharmony_cistatic inline void cpufreq_suspend(void) {}
4828c2ecf20Sopenharmony_cistatic inline void cpufreq_resume(void) {}
4838c2ecf20Sopenharmony_ci#endif
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/*********************************************************************
4868c2ecf20Sopenharmony_ci *                     CPUFREQ NOTIFIER INTERFACE                    *
4878c2ecf20Sopenharmony_ci *********************************************************************/
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci#define CPUFREQ_TRANSITION_NOTIFIER	(0)
4908c2ecf20Sopenharmony_ci#define CPUFREQ_POLICY_NOTIFIER		(1)
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci/* Transition notifiers */
4938c2ecf20Sopenharmony_ci#define CPUFREQ_PRECHANGE		(0)
4948c2ecf20Sopenharmony_ci#define CPUFREQ_POSTCHANGE		(1)
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci/* Policy Notifiers  */
4978c2ecf20Sopenharmony_ci#define CPUFREQ_CREATE_POLICY		(0)
4988c2ecf20Sopenharmony_ci#define CPUFREQ_REMOVE_POLICY		(1)
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_FREQ
5018c2ecf20Sopenharmony_ciint cpufreq_register_notifier(struct notifier_block *nb, unsigned int list);
5028c2ecf20Sopenharmony_ciint cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list);
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_civoid cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
5058c2ecf20Sopenharmony_ci		struct cpufreq_freqs *freqs);
5068c2ecf20Sopenharmony_civoid cpufreq_freq_transition_end(struct cpufreq_policy *policy,
5078c2ecf20Sopenharmony_ci		struct cpufreq_freqs *freqs, int transition_failed);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci#else /* CONFIG_CPU_FREQ */
5108c2ecf20Sopenharmony_cistatic inline int cpufreq_register_notifier(struct notifier_block *nb,
5118c2ecf20Sopenharmony_ci						unsigned int list)
5128c2ecf20Sopenharmony_ci{
5138c2ecf20Sopenharmony_ci	return 0;
5148c2ecf20Sopenharmony_ci}
5158c2ecf20Sopenharmony_cistatic inline int cpufreq_unregister_notifier(struct notifier_block *nb,
5168c2ecf20Sopenharmony_ci						unsigned int list)
5178c2ecf20Sopenharmony_ci{
5188c2ecf20Sopenharmony_ci	return 0;
5198c2ecf20Sopenharmony_ci}
5208c2ecf20Sopenharmony_ci#endif /* !CONFIG_CPU_FREQ */
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci/**
5238c2ecf20Sopenharmony_ci * cpufreq_scale - "old * mult / div" calculation for large values (32-bit-arch
5248c2ecf20Sopenharmony_ci * safe)
5258c2ecf20Sopenharmony_ci * @old:   old value
5268c2ecf20Sopenharmony_ci * @div:   divisor
5278c2ecf20Sopenharmony_ci * @mult:  multiplier
5288c2ecf20Sopenharmony_ci *
5298c2ecf20Sopenharmony_ci *
5308c2ecf20Sopenharmony_ci * new = old * mult / div
5318c2ecf20Sopenharmony_ci */
5328c2ecf20Sopenharmony_cistatic inline unsigned long cpufreq_scale(unsigned long old, u_int div,
5338c2ecf20Sopenharmony_ci		u_int mult)
5348c2ecf20Sopenharmony_ci{
5358c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 32
5368c2ecf20Sopenharmony_ci	u64 result = ((u64) old) * ((u64) mult);
5378c2ecf20Sopenharmony_ci	do_div(result, div);
5388c2ecf20Sopenharmony_ci	return (unsigned long) result;
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci#elif BITS_PER_LONG == 64
5418c2ecf20Sopenharmony_ci	unsigned long result = old * ((u64) mult);
5428c2ecf20Sopenharmony_ci	result /= div;
5438c2ecf20Sopenharmony_ci	return result;
5448c2ecf20Sopenharmony_ci#endif
5458c2ecf20Sopenharmony_ci}
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci/*********************************************************************
5488c2ecf20Sopenharmony_ci *                          CPUFREQ GOVERNORS                        *
5498c2ecf20Sopenharmony_ci *********************************************************************/
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ci#define CPUFREQ_POLICY_UNKNOWN		(0)
5528c2ecf20Sopenharmony_ci/*
5538c2ecf20Sopenharmony_ci * If (cpufreq_driver->target) exists, the ->governor decides what frequency
5548c2ecf20Sopenharmony_ci * within the limits is used. If (cpufreq_driver->setpolicy> exists, these
5558c2ecf20Sopenharmony_ci * two generic policies are available:
5568c2ecf20Sopenharmony_ci */
5578c2ecf20Sopenharmony_ci#define CPUFREQ_POLICY_POWERSAVE	(1)
5588c2ecf20Sopenharmony_ci#define CPUFREQ_POLICY_PERFORMANCE	(2)
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci/*
5618c2ecf20Sopenharmony_ci * The polling frequency depends on the capability of the processor. Default
5628c2ecf20Sopenharmony_ci * polling frequency is 1000 times the transition latency of the processor. The
5638c2ecf20Sopenharmony_ci * ondemand governor will work on any processor with transition latency <= 10ms,
5648c2ecf20Sopenharmony_ci * using appropriate sampling rate.
5658c2ecf20Sopenharmony_ci */
5668c2ecf20Sopenharmony_ci#define LATENCY_MULTIPLIER		(1000)
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_cistruct cpufreq_governor {
5698c2ecf20Sopenharmony_ci	char	name[CPUFREQ_NAME_LEN];
5708c2ecf20Sopenharmony_ci	int	(*init)(struct cpufreq_policy *policy);
5718c2ecf20Sopenharmony_ci	void	(*exit)(struct cpufreq_policy *policy);
5728c2ecf20Sopenharmony_ci	int	(*start)(struct cpufreq_policy *policy);
5738c2ecf20Sopenharmony_ci	void	(*stop)(struct cpufreq_policy *policy);
5748c2ecf20Sopenharmony_ci	void	(*limits)(struct cpufreq_policy *policy);
5758c2ecf20Sopenharmony_ci	ssize_t	(*show_setspeed)	(struct cpufreq_policy *policy,
5768c2ecf20Sopenharmony_ci					 char *buf);
5778c2ecf20Sopenharmony_ci	int	(*store_setspeed)	(struct cpufreq_policy *policy,
5788c2ecf20Sopenharmony_ci					 unsigned int freq);
5798c2ecf20Sopenharmony_ci	struct list_head	governor_list;
5808c2ecf20Sopenharmony_ci	struct module		*owner;
5818c2ecf20Sopenharmony_ci	u8			flags;
5828c2ecf20Sopenharmony_ci};
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci/* Governor flags */
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci/* For governors which change frequency dynamically by themselves */
5878c2ecf20Sopenharmony_ci#define CPUFREQ_GOV_DYNAMIC_SWITCHING	BIT(0)
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci/* For governors wanting the target frequency to be set exactly */
5908c2ecf20Sopenharmony_ci#define CPUFREQ_GOV_STRICT_TARGET	BIT(1)
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci/* Pass a target to the cpufreq driver */
5948c2ecf20Sopenharmony_ciunsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
5958c2ecf20Sopenharmony_ci					unsigned int target_freq);
5968c2ecf20Sopenharmony_ciint cpufreq_driver_target(struct cpufreq_policy *policy,
5978c2ecf20Sopenharmony_ci				 unsigned int target_freq,
5988c2ecf20Sopenharmony_ci				 unsigned int relation);
5998c2ecf20Sopenharmony_ciint __cpufreq_driver_target(struct cpufreq_policy *policy,
6008c2ecf20Sopenharmony_ci				   unsigned int target_freq,
6018c2ecf20Sopenharmony_ci				   unsigned int relation);
6028c2ecf20Sopenharmony_ciunsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
6038c2ecf20Sopenharmony_ci					 unsigned int target_freq);
6048c2ecf20Sopenharmony_ciunsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy);
6058c2ecf20Sopenharmony_ciint cpufreq_register_governor(struct cpufreq_governor *governor);
6068c2ecf20Sopenharmony_civoid cpufreq_unregister_governor(struct cpufreq_governor *governor);
6078c2ecf20Sopenharmony_ciint cpufreq_start_governor(struct cpufreq_policy *policy);
6088c2ecf20Sopenharmony_civoid cpufreq_stop_governor(struct cpufreq_policy *policy);
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci#define cpufreq_governor_init(__governor)			\
6118c2ecf20Sopenharmony_cistatic int __init __governor##_init(void)			\
6128c2ecf20Sopenharmony_ci{								\
6138c2ecf20Sopenharmony_ci	return cpufreq_register_governor(&__governor);	\
6148c2ecf20Sopenharmony_ci}								\
6158c2ecf20Sopenharmony_cicore_initcall(__governor##_init)
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci#define cpufreq_governor_exit(__governor)			\
6188c2ecf20Sopenharmony_cistatic void __exit __governor##_exit(void)			\
6198c2ecf20Sopenharmony_ci{								\
6208c2ecf20Sopenharmony_ci	return cpufreq_unregister_governor(&__governor);	\
6218c2ecf20Sopenharmony_ci}								\
6228c2ecf20Sopenharmony_cimodule_exit(__governor##_exit)
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_cistruct cpufreq_governor *cpufreq_default_governor(void);
6258c2ecf20Sopenharmony_cistruct cpufreq_governor *cpufreq_fallback_governor(void);
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_cistatic inline void cpufreq_policy_apply_limits(struct cpufreq_policy *policy)
6288c2ecf20Sopenharmony_ci{
6298c2ecf20Sopenharmony_ci	if (policy->max < policy->cur)
6308c2ecf20Sopenharmony_ci		__cpufreq_driver_target(policy, policy->max, CPUFREQ_RELATION_H);
6318c2ecf20Sopenharmony_ci	else if (policy->min > policy->cur)
6328c2ecf20Sopenharmony_ci		__cpufreq_driver_target(policy, policy->min, CPUFREQ_RELATION_L);
6338c2ecf20Sopenharmony_ci}
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci/* Governor attribute set */
6368c2ecf20Sopenharmony_cistruct gov_attr_set {
6378c2ecf20Sopenharmony_ci	struct kobject kobj;
6388c2ecf20Sopenharmony_ci	struct list_head policy_list;
6398c2ecf20Sopenharmony_ci	struct mutex update_lock;
6408c2ecf20Sopenharmony_ci	int usage_count;
6418c2ecf20Sopenharmony_ci};
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci/* sysfs ops for cpufreq governors */
6448c2ecf20Sopenharmony_ciextern const struct sysfs_ops governor_sysfs_ops;
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_civoid gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node);
6478c2ecf20Sopenharmony_civoid gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node);
6488c2ecf20Sopenharmony_ciunsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node);
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci/* Governor sysfs attribute */
6518c2ecf20Sopenharmony_cistruct governor_attr {
6528c2ecf20Sopenharmony_ci	struct attribute attr;
6538c2ecf20Sopenharmony_ci	ssize_t (*show)(struct gov_attr_set *attr_set, char *buf);
6548c2ecf20Sopenharmony_ci	ssize_t (*store)(struct gov_attr_set *attr_set, const char *buf,
6558c2ecf20Sopenharmony_ci			 size_t count);
6568c2ecf20Sopenharmony_ci};
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci/*********************************************************************
6598c2ecf20Sopenharmony_ci *                     FREQUENCY TABLE HELPERS                       *
6608c2ecf20Sopenharmony_ci *********************************************************************/
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci/* Special Values of .frequency field */
6638c2ecf20Sopenharmony_ci#define CPUFREQ_ENTRY_INVALID	~0u
6648c2ecf20Sopenharmony_ci#define CPUFREQ_TABLE_END	~1u
6658c2ecf20Sopenharmony_ci/* Special Values of .flags field */
6668c2ecf20Sopenharmony_ci#define CPUFREQ_BOOST_FREQ	(1 << 0)
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistruct cpufreq_frequency_table {
6698c2ecf20Sopenharmony_ci	unsigned int	flags;
6708c2ecf20Sopenharmony_ci	unsigned int	driver_data; /* driver specific data, not used by core */
6718c2ecf20Sopenharmony_ci	unsigned int	frequency; /* kHz - doesn't need to be in ascending
6728c2ecf20Sopenharmony_ci				    * order */
6738c2ecf20Sopenharmony_ci};
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci#if defined(CONFIG_CPU_FREQ) && defined(CONFIG_PM_OPP)
6768c2ecf20Sopenharmony_ciint dev_pm_opp_init_cpufreq_table(struct device *dev,
6778c2ecf20Sopenharmony_ci				  struct cpufreq_frequency_table **table);
6788c2ecf20Sopenharmony_civoid dev_pm_opp_free_cpufreq_table(struct device *dev,
6798c2ecf20Sopenharmony_ci				   struct cpufreq_frequency_table **table);
6808c2ecf20Sopenharmony_ci#else
6818c2ecf20Sopenharmony_cistatic inline int dev_pm_opp_init_cpufreq_table(struct device *dev,
6828c2ecf20Sopenharmony_ci						struct cpufreq_frequency_table
6838c2ecf20Sopenharmony_ci						**table)
6848c2ecf20Sopenharmony_ci{
6858c2ecf20Sopenharmony_ci	return -EINVAL;
6868c2ecf20Sopenharmony_ci}
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_cistatic inline void dev_pm_opp_free_cpufreq_table(struct device *dev,
6898c2ecf20Sopenharmony_ci						 struct cpufreq_frequency_table
6908c2ecf20Sopenharmony_ci						 **table)
6918c2ecf20Sopenharmony_ci{
6928c2ecf20Sopenharmony_ci}
6938c2ecf20Sopenharmony_ci#endif
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci/*
6968c2ecf20Sopenharmony_ci * cpufreq_for_each_entry -	iterate over a cpufreq_frequency_table
6978c2ecf20Sopenharmony_ci * @pos:	the cpufreq_frequency_table * to use as a loop cursor.
6988c2ecf20Sopenharmony_ci * @table:	the cpufreq_frequency_table * to iterate over.
6998c2ecf20Sopenharmony_ci */
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci#define cpufreq_for_each_entry(pos, table)	\
7028c2ecf20Sopenharmony_ci	for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++)
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci/*
7058c2ecf20Sopenharmony_ci * cpufreq_for_each_entry_idx -	iterate over a cpufreq_frequency_table
7068c2ecf20Sopenharmony_ci *	with index
7078c2ecf20Sopenharmony_ci * @pos:	the cpufreq_frequency_table * to use as a loop cursor.
7088c2ecf20Sopenharmony_ci * @table:	the cpufreq_frequency_table * to iterate over.
7098c2ecf20Sopenharmony_ci * @idx:	the table entry currently being processed
7108c2ecf20Sopenharmony_ci */
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci#define cpufreq_for_each_entry_idx(pos, table, idx)	\
7138c2ecf20Sopenharmony_ci	for (pos = table, idx = 0; pos->frequency != CPUFREQ_TABLE_END; \
7148c2ecf20Sopenharmony_ci		pos++, idx++)
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci/*
7178c2ecf20Sopenharmony_ci * cpufreq_for_each_valid_entry -     iterate over a cpufreq_frequency_table
7188c2ecf20Sopenharmony_ci *	excluding CPUFREQ_ENTRY_INVALID frequencies.
7198c2ecf20Sopenharmony_ci * @pos:        the cpufreq_frequency_table * to use as a loop cursor.
7208c2ecf20Sopenharmony_ci * @table:      the cpufreq_frequency_table * to iterate over.
7218c2ecf20Sopenharmony_ci */
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci#define cpufreq_for_each_valid_entry(pos, table)			\
7248c2ecf20Sopenharmony_ci	for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++)	\
7258c2ecf20Sopenharmony_ci		if (pos->frequency == CPUFREQ_ENTRY_INVALID)		\
7268c2ecf20Sopenharmony_ci			continue;					\
7278c2ecf20Sopenharmony_ci		else
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci/*
7308c2ecf20Sopenharmony_ci * cpufreq_for_each_valid_entry_idx -     iterate with index over a cpufreq
7318c2ecf20Sopenharmony_ci *	frequency_table excluding CPUFREQ_ENTRY_INVALID frequencies.
7328c2ecf20Sopenharmony_ci * @pos:	the cpufreq_frequency_table * to use as a loop cursor.
7338c2ecf20Sopenharmony_ci * @table:	the cpufreq_frequency_table * to iterate over.
7348c2ecf20Sopenharmony_ci * @idx:	the table entry currently being processed
7358c2ecf20Sopenharmony_ci */
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci#define cpufreq_for_each_valid_entry_idx(pos, table, idx)		\
7388c2ecf20Sopenharmony_ci	cpufreq_for_each_entry_idx(pos, table, idx)			\
7398c2ecf20Sopenharmony_ci		if (pos->frequency == CPUFREQ_ENTRY_INVALID)		\
7408c2ecf20Sopenharmony_ci			continue;					\
7418c2ecf20Sopenharmony_ci		else
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ciint cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
7458c2ecf20Sopenharmony_ci				    struct cpufreq_frequency_table *table);
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_ciint cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy,
7488c2ecf20Sopenharmony_ci				   struct cpufreq_frequency_table *table);
7498c2ecf20Sopenharmony_ciint cpufreq_generic_frequency_table_verify(struct cpufreq_policy_data *policy);
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ciint cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
7528c2ecf20Sopenharmony_ci				 unsigned int target_freq,
7538c2ecf20Sopenharmony_ci				 unsigned int relation);
7548c2ecf20Sopenharmony_ciint cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
7558c2ecf20Sopenharmony_ci		unsigned int freq);
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_cissize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_FREQ
7608c2ecf20Sopenharmony_ciint cpufreq_boost_trigger_state(int state);
7618c2ecf20Sopenharmony_ciint cpufreq_boost_enabled(void);
7628c2ecf20Sopenharmony_ciint cpufreq_enable_boost_support(void);
7638c2ecf20Sopenharmony_cibool policy_has_boost_freq(struct cpufreq_policy *policy);
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_ci/* Find lowest freq at or above target in a table in ascending order */
7668c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_al(struct cpufreq_policy *policy,
7678c2ecf20Sopenharmony_ci					      unsigned int target_freq)
7688c2ecf20Sopenharmony_ci{
7698c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *table = policy->freq_table;
7708c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
7718c2ecf20Sopenharmony_ci	unsigned int freq;
7728c2ecf20Sopenharmony_ci	int idx, best = -1;
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry_idx(pos, table, idx) {
7758c2ecf20Sopenharmony_ci		freq = pos->frequency;
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci		if (freq >= target_freq)
7788c2ecf20Sopenharmony_ci			return idx;
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci		best = idx;
7818c2ecf20Sopenharmony_ci	}
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	return best;
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci/* Find lowest freq at or above target in a table in descending order */
7878c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_dl(struct cpufreq_policy *policy,
7888c2ecf20Sopenharmony_ci					      unsigned int target_freq)
7898c2ecf20Sopenharmony_ci{
7908c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *table = policy->freq_table;
7918c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
7928c2ecf20Sopenharmony_ci	unsigned int freq;
7938c2ecf20Sopenharmony_ci	int idx, best = -1;
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry_idx(pos, table, idx) {
7968c2ecf20Sopenharmony_ci		freq = pos->frequency;
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci		if (freq == target_freq)
7998c2ecf20Sopenharmony_ci			return idx;
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci		if (freq > target_freq) {
8028c2ecf20Sopenharmony_ci			best = idx;
8038c2ecf20Sopenharmony_ci			continue;
8048c2ecf20Sopenharmony_ci		}
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci		/* No freq found above target_freq */
8078c2ecf20Sopenharmony_ci		if (best == -1)
8088c2ecf20Sopenharmony_ci			return idx;
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_ci		return best;
8118c2ecf20Sopenharmony_ci	}
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	return best;
8148c2ecf20Sopenharmony_ci}
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci/* Works only on sorted freq-tables */
8178c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_l(struct cpufreq_policy *policy,
8188c2ecf20Sopenharmony_ci					     unsigned int target_freq)
8198c2ecf20Sopenharmony_ci{
8208c2ecf20Sopenharmony_ci	target_freq = clamp_val(target_freq, policy->min, policy->max);
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci	if (policy->freq_table_sorted == CPUFREQ_TABLE_SORTED_ASCENDING)
8238c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_al(policy, target_freq);
8248c2ecf20Sopenharmony_ci	else
8258c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_dl(policy, target_freq);
8268c2ecf20Sopenharmony_ci}
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci/* Find highest freq at or below target in a table in ascending order */
8298c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_ah(struct cpufreq_policy *policy,
8308c2ecf20Sopenharmony_ci					      unsigned int target_freq)
8318c2ecf20Sopenharmony_ci{
8328c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *table = policy->freq_table;
8338c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
8348c2ecf20Sopenharmony_ci	unsigned int freq;
8358c2ecf20Sopenharmony_ci	int idx, best = -1;
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry_idx(pos, table, idx) {
8388c2ecf20Sopenharmony_ci		freq = pos->frequency;
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_ci		if (freq == target_freq)
8418c2ecf20Sopenharmony_ci			return idx;
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci		if (freq < target_freq) {
8448c2ecf20Sopenharmony_ci			best = idx;
8458c2ecf20Sopenharmony_ci			continue;
8468c2ecf20Sopenharmony_ci		}
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci		/* No freq found below target_freq */
8498c2ecf20Sopenharmony_ci		if (best == -1)
8508c2ecf20Sopenharmony_ci			return idx;
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci		return best;
8538c2ecf20Sopenharmony_ci	}
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	return best;
8568c2ecf20Sopenharmony_ci}
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci/* Find highest freq at or below target in a table in descending order */
8598c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_dh(struct cpufreq_policy *policy,
8608c2ecf20Sopenharmony_ci					      unsigned int target_freq)
8618c2ecf20Sopenharmony_ci{
8628c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *table = policy->freq_table;
8638c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
8648c2ecf20Sopenharmony_ci	unsigned int freq;
8658c2ecf20Sopenharmony_ci	int idx, best = -1;
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry_idx(pos, table, idx) {
8688c2ecf20Sopenharmony_ci		freq = pos->frequency;
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci		if (freq <= target_freq)
8718c2ecf20Sopenharmony_ci			return idx;
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_ci		best = idx;
8748c2ecf20Sopenharmony_ci	}
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_ci	return best;
8778c2ecf20Sopenharmony_ci}
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci/* Works only on sorted freq-tables */
8808c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_h(struct cpufreq_policy *policy,
8818c2ecf20Sopenharmony_ci					     unsigned int target_freq)
8828c2ecf20Sopenharmony_ci{
8838c2ecf20Sopenharmony_ci	target_freq = clamp_val(target_freq, policy->min, policy->max);
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci	if (policy->freq_table_sorted == CPUFREQ_TABLE_SORTED_ASCENDING)
8868c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_ah(policy, target_freq);
8878c2ecf20Sopenharmony_ci	else
8888c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_dh(policy, target_freq);
8898c2ecf20Sopenharmony_ci}
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_ci/* Find closest freq to target in a table in ascending order */
8928c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_ac(struct cpufreq_policy *policy,
8938c2ecf20Sopenharmony_ci					      unsigned int target_freq)
8948c2ecf20Sopenharmony_ci{
8958c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *table = policy->freq_table;
8968c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
8978c2ecf20Sopenharmony_ci	unsigned int freq;
8988c2ecf20Sopenharmony_ci	int idx, best = -1;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry_idx(pos, table, idx) {
9018c2ecf20Sopenharmony_ci		freq = pos->frequency;
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci		if (freq == target_freq)
9048c2ecf20Sopenharmony_ci			return idx;
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci		if (freq < target_freq) {
9078c2ecf20Sopenharmony_ci			best = idx;
9088c2ecf20Sopenharmony_ci			continue;
9098c2ecf20Sopenharmony_ci		}
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci		/* No freq found below target_freq */
9128c2ecf20Sopenharmony_ci		if (best == -1)
9138c2ecf20Sopenharmony_ci			return idx;
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci		/* Choose the closest freq */
9168c2ecf20Sopenharmony_ci		if (target_freq - table[best].frequency > freq - target_freq)
9178c2ecf20Sopenharmony_ci			return idx;
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci		return best;
9208c2ecf20Sopenharmony_ci	}
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	return best;
9238c2ecf20Sopenharmony_ci}
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci/* Find closest freq to target in a table in descending order */
9268c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_dc(struct cpufreq_policy *policy,
9278c2ecf20Sopenharmony_ci					      unsigned int target_freq)
9288c2ecf20Sopenharmony_ci{
9298c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *table = policy->freq_table;
9308c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
9318c2ecf20Sopenharmony_ci	unsigned int freq;
9328c2ecf20Sopenharmony_ci	int idx, best = -1;
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry_idx(pos, table, idx) {
9358c2ecf20Sopenharmony_ci		freq = pos->frequency;
9368c2ecf20Sopenharmony_ci
9378c2ecf20Sopenharmony_ci		if (freq == target_freq)
9388c2ecf20Sopenharmony_ci			return idx;
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_ci		if (freq > target_freq) {
9418c2ecf20Sopenharmony_ci			best = idx;
9428c2ecf20Sopenharmony_ci			continue;
9438c2ecf20Sopenharmony_ci		}
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci		/* No freq found above target_freq */
9468c2ecf20Sopenharmony_ci		if (best == -1)
9478c2ecf20Sopenharmony_ci			return idx;
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci		/* Choose the closest freq */
9508c2ecf20Sopenharmony_ci		if (table[best].frequency - target_freq > target_freq - freq)
9518c2ecf20Sopenharmony_ci			return idx;
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_ci		return best;
9548c2ecf20Sopenharmony_ci	}
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ci	return best;
9578c2ecf20Sopenharmony_ci}
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci/* Works only on sorted freq-tables */
9608c2ecf20Sopenharmony_cistatic inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
9618c2ecf20Sopenharmony_ci					     unsigned int target_freq)
9628c2ecf20Sopenharmony_ci{
9638c2ecf20Sopenharmony_ci	target_freq = clamp_val(target_freq, policy->min, policy->max);
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci	if (policy->freq_table_sorted == CPUFREQ_TABLE_SORTED_ASCENDING)
9668c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_ac(policy, target_freq);
9678c2ecf20Sopenharmony_ci	else
9688c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_dc(policy, target_freq);
9698c2ecf20Sopenharmony_ci}
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_cistatic inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
9728c2ecf20Sopenharmony_ci						 unsigned int target_freq,
9738c2ecf20Sopenharmony_ci						 unsigned int relation)
9748c2ecf20Sopenharmony_ci{
9758c2ecf20Sopenharmony_ci	if (unlikely(policy->freq_table_sorted == CPUFREQ_TABLE_UNSORTED))
9768c2ecf20Sopenharmony_ci		return cpufreq_table_index_unsorted(policy, target_freq,
9778c2ecf20Sopenharmony_ci						    relation);
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_ci	switch (relation) {
9808c2ecf20Sopenharmony_ci	case CPUFREQ_RELATION_L:
9818c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_l(policy, target_freq);
9828c2ecf20Sopenharmony_ci	case CPUFREQ_RELATION_H:
9838c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_h(policy, target_freq);
9848c2ecf20Sopenharmony_ci	case CPUFREQ_RELATION_C:
9858c2ecf20Sopenharmony_ci		return cpufreq_table_find_index_c(policy, target_freq);
9868c2ecf20Sopenharmony_ci	default:
9878c2ecf20Sopenharmony_ci		WARN_ON_ONCE(1);
9888c2ecf20Sopenharmony_ci		return 0;
9898c2ecf20Sopenharmony_ci	}
9908c2ecf20Sopenharmony_ci}
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_cistatic inline int cpufreq_table_count_valid_entries(const struct cpufreq_policy *policy)
9938c2ecf20Sopenharmony_ci{
9948c2ecf20Sopenharmony_ci	struct cpufreq_frequency_table *pos;
9958c2ecf20Sopenharmony_ci	int count = 0;
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_ci	if (unlikely(!policy->freq_table))
9988c2ecf20Sopenharmony_ci		return 0;
9998c2ecf20Sopenharmony_ci
10008c2ecf20Sopenharmony_ci	cpufreq_for_each_valid_entry(pos, policy->freq_table)
10018c2ecf20Sopenharmony_ci		count++;
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci	return count;
10048c2ecf20Sopenharmony_ci}
10058c2ecf20Sopenharmony_ci#else
10068c2ecf20Sopenharmony_cistatic inline int cpufreq_boost_trigger_state(int state)
10078c2ecf20Sopenharmony_ci{
10088c2ecf20Sopenharmony_ci	return 0;
10098c2ecf20Sopenharmony_ci}
10108c2ecf20Sopenharmony_cistatic inline int cpufreq_boost_enabled(void)
10118c2ecf20Sopenharmony_ci{
10128c2ecf20Sopenharmony_ci	return 0;
10138c2ecf20Sopenharmony_ci}
10148c2ecf20Sopenharmony_ci
10158c2ecf20Sopenharmony_cistatic inline int cpufreq_enable_boost_support(void)
10168c2ecf20Sopenharmony_ci{
10178c2ecf20Sopenharmony_ci	return -EINVAL;
10188c2ecf20Sopenharmony_ci}
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_cistatic inline bool policy_has_boost_freq(struct cpufreq_policy *policy)
10218c2ecf20Sopenharmony_ci{
10228c2ecf20Sopenharmony_ci	return false;
10238c2ecf20Sopenharmony_ci}
10248c2ecf20Sopenharmony_ci#endif
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
10278c2ecf20Sopenharmony_civoid sched_cpufreq_governor_change(struct cpufreq_policy *policy,
10288c2ecf20Sopenharmony_ci			struct cpufreq_governor *old_gov);
10298c2ecf20Sopenharmony_ci#else
10308c2ecf20Sopenharmony_cistatic inline void sched_cpufreq_governor_change(struct cpufreq_policy *policy,
10318c2ecf20Sopenharmony_ci			struct cpufreq_governor *old_gov) { }
10328c2ecf20Sopenharmony_ci#endif
10338c2ecf20Sopenharmony_ci
10348c2ecf20Sopenharmony_ciextern void arch_freq_prepare_all(void);
10358c2ecf20Sopenharmony_ciextern unsigned int arch_freq_get_on_cpu(int cpu);
10368c2ecf20Sopenharmony_ci
10378c2ecf20Sopenharmony_ci#ifndef arch_set_freq_scale
10388c2ecf20Sopenharmony_cistatic __always_inline
10398c2ecf20Sopenharmony_civoid arch_set_freq_scale(const struct cpumask *cpus,
10408c2ecf20Sopenharmony_ci			 unsigned long cur_freq,
10418c2ecf20Sopenharmony_ci			 unsigned long max_freq)
10428c2ecf20Sopenharmony_ci{
10438c2ecf20Sopenharmony_ci}
10448c2ecf20Sopenharmony_ci#endif
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci/* the following are really really optional */
10478c2ecf20Sopenharmony_ciextern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
10488c2ecf20Sopenharmony_ciextern struct freq_attr cpufreq_freq_attr_scaling_boost_freqs;
10498c2ecf20Sopenharmony_ciextern struct freq_attr *cpufreq_generic_attr[];
10508c2ecf20Sopenharmony_ciint cpufreq_table_validate_and_sort(struct cpufreq_policy *policy);
10518c2ecf20Sopenharmony_ci
10528c2ecf20Sopenharmony_ciunsigned int cpufreq_generic_get(unsigned int cpu);
10538c2ecf20Sopenharmony_civoid cpufreq_generic_init(struct cpufreq_policy *policy,
10548c2ecf20Sopenharmony_ci		struct cpufreq_frequency_table *table,
10558c2ecf20Sopenharmony_ci		unsigned int transition_latency);
10568c2ecf20Sopenharmony_ci#endif /* _LINUX_CPUFREQ_H */
1057