cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

pm_opp.h (16576B)


      1/* SPDX-License-Identifier: GPL-2.0-only */
      2/*
      3 * Generic OPP Interface
      4 *
      5 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
      6 *	Nishanth Menon
      7 *	Romit Dasgupta
      8 *	Kevin Hilman
      9 */
     10
     11#ifndef __LINUX_OPP_H__
     12#define __LINUX_OPP_H__
     13
     14#include <linux/energy_model.h>
     15#include <linux/err.h>
     16#include <linux/notifier.h>
     17
     18struct clk;
     19struct regulator;
     20struct dev_pm_opp;
     21struct device;
     22struct opp_table;
     23
     24enum dev_pm_opp_event {
     25	OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
     26	OPP_EVENT_ADJUST_VOLTAGE,
     27};
     28
     29/**
     30 * struct dev_pm_opp_supply - Power supply voltage/current values
     31 * @u_volt:	Target voltage in microvolts corresponding to this OPP
     32 * @u_volt_min:	Minimum voltage in microvolts corresponding to this OPP
     33 * @u_volt_max:	Maximum voltage in microvolts corresponding to this OPP
     34 * @u_amp:	Maximum current drawn by the device in microamperes
     35 * @u_watt:	Power used by the device in microwatts
     36 *
     37 * This structure stores the voltage/current/power values for a single power
     38 * supply.
     39 */
     40struct dev_pm_opp_supply {
     41	unsigned long u_volt;
     42	unsigned long u_volt_min;
     43	unsigned long u_volt_max;
     44	unsigned long u_amp;
     45	unsigned long u_watt;
     46};
     47
     48/**
     49 * struct dev_pm_opp_icc_bw - Interconnect bandwidth values
     50 * @avg:	Average bandwidth corresponding to this OPP (in icc units)
     51 * @peak:	Peak bandwidth corresponding to this OPP (in icc units)
     52 *
     53 * This structure stores the bandwidth values for a single interconnect path.
     54 */
     55struct dev_pm_opp_icc_bw {
     56	u32 avg;
     57	u32 peak;
     58};
     59
     60/**
     61 * struct dev_pm_opp_info - OPP freq/voltage/current values
     62 * @rate:	Target clk rate in hz
     63 * @supplies:	Array of voltage/current values for all power supplies
     64 *
     65 * This structure stores the freq/voltage/current values for a single OPP.
     66 */
     67struct dev_pm_opp_info {
     68	unsigned long rate;
     69	struct dev_pm_opp_supply *supplies;
     70};
     71
     72/**
     73 * struct dev_pm_set_opp_data - Set OPP data
     74 * @old_opp:	Old OPP info
     75 * @new_opp:	New OPP info
     76 * @regulators:	Array of regulator pointers
     77 * @regulator_count: Number of regulators
     78 * @clk:	Pointer to clk
     79 * @dev:	Pointer to the struct device
     80 *
     81 * This structure contains all information required for setting an OPP.
     82 */
     83struct dev_pm_set_opp_data {
     84	struct dev_pm_opp_info old_opp;
     85	struct dev_pm_opp_info new_opp;
     86
     87	struct regulator **regulators;
     88	unsigned int regulator_count;
     89	struct clk *clk;
     90	struct device *dev;
     91};
     92
     93#if defined(CONFIG_PM_OPP)
     94
     95struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
     96void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
     97
     98unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
     99
    100unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
    101
    102unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
    103
    104unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
    105
    106unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
    107					    unsigned int index);
    108
    109bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
    110
    111int dev_pm_opp_get_opp_count(struct device *dev);
    112unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
    113unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
    114unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
    115unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
    116
    117struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
    118					      unsigned long freq,
    119					      bool available);
    120struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
    121					      unsigned long *freq);
    122struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
    123						     unsigned long u_volt);
    124
    125struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
    126					       unsigned int level);
    127struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
    128					      unsigned int *level);
    129
    130struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
    131					     unsigned long *freq);
    132
    133struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
    134					   unsigned int *bw, int index);
    135
    136struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
    137					   unsigned int *bw, int index);
    138
    139void dev_pm_opp_put(struct dev_pm_opp *opp);
    140
    141int dev_pm_opp_add(struct device *dev, unsigned long freq,
    142		   unsigned long u_volt);
    143void dev_pm_opp_remove(struct device *dev, unsigned long freq);
    144void dev_pm_opp_remove_all_dynamic(struct device *dev);
    145
    146int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
    147			      unsigned long u_volt, unsigned long u_volt_min,
    148			      unsigned long u_volt_max);
    149
    150int dev_pm_opp_enable(struct device *dev, unsigned long freq);
    151
    152int dev_pm_opp_disable(struct device *dev, unsigned long freq);
    153
    154int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
    155int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
    156
    157struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
    158void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
    159int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
    160struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
    161void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
    162struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
    163void dev_pm_opp_put_regulators(struct opp_table *opp_table);
    164int devm_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
    165struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
    166void dev_pm_opp_put_clkname(struct opp_table *opp_table);
    167int devm_pm_opp_set_clkname(struct device *dev, const char *name);
    168struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
    169void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
    170int devm_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
    171struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs);
    172void dev_pm_opp_detach_genpd(struct opp_table *opp_table);
    173int devm_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs);
    174struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp);
    175int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
    176int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
    177int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
    178int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
    179int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
    180void dev_pm_opp_remove_table(struct device *dev);
    181void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
    182int dev_pm_opp_sync_regulators(struct device *dev);
    183#else
    184static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
    185{
    186	return ERR_PTR(-EOPNOTSUPP);
    187}
    188
    189static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
    190{
    191	return ERR_PTR(-EOPNOTSUPP);
    192}
    193
    194static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
    195
    196static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
    197{
    198	return 0;
    199}
    200
    201static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
    202{
    203	return 0;
    204}
    205
    206static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
    207{
    208	return 0;
    209}
    210
    211static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
    212{
    213	return 0;
    214}
    215
    216static inline
    217unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
    218					    unsigned int index)
    219{
    220	return 0;
    221}
    222
    223static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
    224{
    225	return false;
    226}
    227
    228static inline int dev_pm_opp_get_opp_count(struct device *dev)
    229{
    230	return 0;
    231}
    232
    233static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
    234{
    235	return 0;
    236}
    237
    238static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
    239{
    240	return 0;
    241}
    242
    243static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
    244{
    245	return 0;
    246}
    247
    248static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
    249{
    250	return 0;
    251}
    252
    253static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
    254					unsigned int level)
    255{
    256	return ERR_PTR(-EOPNOTSUPP);
    257}
    258
    259static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
    260					unsigned int *level)
    261{
    262	return ERR_PTR(-EOPNOTSUPP);
    263}
    264
    265static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
    266					unsigned long freq, bool available)
    267{
    268	return ERR_PTR(-EOPNOTSUPP);
    269}
    270
    271static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
    272					unsigned long *freq)
    273{
    274	return ERR_PTR(-EOPNOTSUPP);
    275}
    276
    277static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
    278					unsigned long u_volt)
    279{
    280	return ERR_PTR(-EOPNOTSUPP);
    281}
    282
    283static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
    284					unsigned long *freq)
    285{
    286	return ERR_PTR(-EOPNOTSUPP);
    287}
    288
    289static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
    290					unsigned int *bw, int index)
    291{
    292	return ERR_PTR(-EOPNOTSUPP);
    293}
    294
    295static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
    296					unsigned int *bw, int index)
    297{
    298	return ERR_PTR(-EOPNOTSUPP);
    299}
    300
    301static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
    302
    303static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
    304					unsigned long u_volt)
    305{
    306	return -EOPNOTSUPP;
    307}
    308
    309static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
    310{
    311}
    312
    313static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
    314{
    315}
    316
    317static inline int
    318dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
    319			  unsigned long u_volt, unsigned long u_volt_min,
    320			  unsigned long u_volt_max)
    321{
    322	return 0;
    323}
    324
    325static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
    326{
    327	return 0;
    328}
    329
    330static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
    331{
    332	return 0;
    333}
    334
    335static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
    336{
    337	return -EOPNOTSUPP;
    338}
    339
    340static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
    341{
    342	return -EOPNOTSUPP;
    343}
    344
    345static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
    346							    const u32 *versions,
    347							    unsigned int count)
    348{
    349	return ERR_PTR(-EOPNOTSUPP);
    350}
    351
    352static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
    353
    354static inline int devm_pm_opp_set_supported_hw(struct device *dev,
    355					       const u32 *versions,
    356					       unsigned int count)
    357{
    358	return -EOPNOTSUPP;
    359}
    360
    361static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
    362			int (*set_opp)(struct dev_pm_set_opp_data *data))
    363{
    364	return ERR_PTR(-EOPNOTSUPP);
    365}
    366
    367static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
    368
    369static inline int devm_pm_opp_register_set_opp_helper(struct device *dev,
    370				    int (*set_opp)(struct dev_pm_set_opp_data *data))
    371{
    372	return -EOPNOTSUPP;
    373}
    374
    375static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
    376{
    377	return ERR_PTR(-EOPNOTSUPP);
    378}
    379
    380static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
    381
    382static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
    383{
    384	return ERR_PTR(-EOPNOTSUPP);
    385}
    386
    387static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
    388
    389static inline int devm_pm_opp_set_regulators(struct device *dev,
    390					     const char * const names[],
    391					     unsigned int count)
    392{
    393	return -EOPNOTSUPP;
    394}
    395
    396static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
    397{
    398	return ERR_PTR(-EOPNOTSUPP);
    399}
    400
    401static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
    402
    403static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
    404{
    405	return -EOPNOTSUPP;
    406}
    407
    408static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char * const *names, struct device ***virt_devs)
    409{
    410	return ERR_PTR(-EOPNOTSUPP);
    411}
    412
    413static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
    414
    415static inline int devm_pm_opp_attach_genpd(struct device *dev,
    416					   const char * const *names,
    417					   struct device ***virt_devs)
    418{
    419	return -EOPNOTSUPP;
    420}
    421
    422static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
    423				struct opp_table *dst_table, struct dev_pm_opp *src_opp)
    424{
    425	return ERR_PTR(-EOPNOTSUPP);
    426}
    427
    428static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
    429{
    430	return -EOPNOTSUPP;
    431}
    432
    433static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
    434{
    435	return -EOPNOTSUPP;
    436}
    437
    438static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
    439{
    440	return -EOPNOTSUPP;
    441}
    442
    443static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
    444{
    445	return -EOPNOTSUPP;
    446}
    447
    448static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
    449{
    450	return -EINVAL;
    451}
    452
    453static inline void dev_pm_opp_remove_table(struct device *dev)
    454{
    455}
    456
    457static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
    458{
    459}
    460
    461static inline int dev_pm_opp_sync_regulators(struct device *dev)
    462{
    463	return -EOPNOTSUPP;
    464}
    465
    466#endif		/* CONFIG_PM_OPP */
    467
    468#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
    469int dev_pm_opp_of_add_table(struct device *dev);
    470int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
    471int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
    472int dev_pm_opp_of_add_table_noclk(struct device *dev, int index);
    473int devm_pm_opp_of_add_table_noclk(struct device *dev, int index);
    474void dev_pm_opp_of_remove_table(struct device *dev);
    475int devm_pm_opp_of_add_table(struct device *dev);
    476int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
    477void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
    478int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
    479struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
    480struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
    481int of_get_required_opp_performance_state(struct device_node *np, int index);
    482int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
    483int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
    484static inline void dev_pm_opp_of_unregister_em(struct device *dev)
    485{
    486	em_dev_unregister_perf_domain(dev);
    487}
    488#else
    489static inline int dev_pm_opp_of_add_table(struct device *dev)
    490{
    491	return -EOPNOTSUPP;
    492}
    493
    494static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
    495{
    496	return -EOPNOTSUPP;
    497}
    498
    499static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
    500{
    501	return -EOPNOTSUPP;
    502}
    503
    504static inline int dev_pm_opp_of_add_table_noclk(struct device *dev, int index)
    505{
    506	return -EOPNOTSUPP;
    507}
    508
    509static inline int devm_pm_opp_of_add_table_noclk(struct device *dev, int index)
    510{
    511	return -EOPNOTSUPP;
    512}
    513
    514static inline void dev_pm_opp_of_remove_table(struct device *dev)
    515{
    516}
    517
    518static inline int devm_pm_opp_of_add_table(struct device *dev)
    519{
    520	return -EOPNOTSUPP;
    521}
    522
    523static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
    524{
    525	return -EOPNOTSUPP;
    526}
    527
    528static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
    529{
    530}
    531
    532static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
    533{
    534	return -EOPNOTSUPP;
    535}
    536
    537static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
    538{
    539	return NULL;
    540}
    541
    542static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
    543{
    544	return NULL;
    545}
    546
    547static inline int dev_pm_opp_of_register_em(struct device *dev,
    548					    struct cpumask *cpus)
    549{
    550	return -EOPNOTSUPP;
    551}
    552
    553static inline void dev_pm_opp_of_unregister_em(struct device *dev)
    554{
    555}
    556
    557static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
    558{
    559	return -EOPNOTSUPP;
    560}
    561
    562static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
    563{
    564	return -EOPNOTSUPP;
    565}
    566#endif
    567
    568#endif		/* __LINUX_OPP_H__ */