core.c (db6da59cf27b5661ced03754ae0550f8914eda9e) core.c (84cb7ff35fcf7c0b552f553a3f2db9c3e92fc707)
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

--- 15 unchanged lines hidden (view full) ---

24
25/*
26 * The root of the list of all opp-tables. All opp_table structures branch off
27 * from here, with each opp_table containing the list of opps it supports in
28 * various states of availability.
29 */
30LIST_HEAD(opp_tables);
31
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

--- 15 unchanged lines hidden (view full) ---

24
25/*
26 * The root of the list of all opp-tables. All opp_table structures branch off
27 * from here, with each opp_table containing the list of opps it supports in
28 * various states of availability.
29 */
30LIST_HEAD(opp_tables);
31
32/* OPP tables with uninitialized required OPPs */
33LIST_HEAD(lazy_opp_tables);
34
35/* Lock to allow exclusive modification to the device and opp lists */
36DEFINE_MUTEX(opp_table_lock);
37/* Flag indicating that opp_tables list is being updated at the moment */
38static bool opp_tables_busy;
39
40/* OPP ID allocator */
41static DEFINE_XARRAY_ALLOC1(opp_configs);
42

--- 182 unchanged lines hidden (view full) ---

225 * @index: index of the required opp
226 *
227 * Return: performance state read from device tree corresponding to the
228 * required opp, else return 0.
229 */
230unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
231 unsigned int index)
232{
32/* Lock to allow exclusive modification to the device and opp lists */
33DEFINE_MUTEX(opp_table_lock);
34/* Flag indicating that opp_tables list is being updated at the moment */
35static bool opp_tables_busy;
36
37/* OPP ID allocator */
38static DEFINE_XARRAY_ALLOC1(opp_configs);
39

--- 182 unchanged lines hidden (view full) ---

222 * @index: index of the required opp
223 *
224 * Return: performance state read from device tree corresponding to the
225 * required opp, else return 0.
226 */
227unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
228 unsigned int index)
229{
230 struct opp_table *opp_table = opp->opp_table;
231
233 if (IS_ERR_OR_NULL(opp) || !opp->available ||
232 if (IS_ERR_OR_NULL(opp) || !opp->available ||
234 index >= opp->opp_table->required_opp_count) {
233 index >= opp_table->required_opp_count) {
235 pr_err("%s: Invalid parameters\n", __func__);
236 return 0;
237 }
238
239 /* required-opps not fully initialized yet */
234 pr_err("%s: Invalid parameters\n", __func__);
235 return 0;
236 }
237
238 /* required-opps not fully initialized yet */
240 if (lazy_linking_pending(opp->opp_table))
239 if (lazy_linking_pending(opp_table))
241 return 0;
242
240 return 0;
241
242 /* The required OPP table must belong to a genpd */
243 if (unlikely(!opp_table->required_opp_tables[index]->is_genpd)) {
244 pr_err("%s: Performance state is only valid for genpds.\n", __func__);
245 return 0;
246 }
247
243 return opp->required_opps[index]->pstate;
244}
245EXPORT_SYMBOL_GPL(dev_pm_opp_get_required_pstate);
246
247/**
248 * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not
249 * @opp: opp for which turbo mode is being verified
250 *

--- 835 unchanged lines hidden (view full) ---

1086 /* Find the currently set OPP if we don't know already */
1087 if (unlikely(!opp_table->current_opp))
1088 _find_current_opp(dev, opp_table);
1089
1090 old_opp = opp_table->current_opp;
1091
1092 /* Return early if nothing to do */
1093 if (!forced && old_opp == opp && opp_table->enabled) {
248 return opp->required_opps[index]->pstate;
249}
250EXPORT_SYMBOL_GPL(dev_pm_opp_get_required_pstate);
251
252/**
253 * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not
254 * @opp: opp for which turbo mode is being verified
255 *

--- 835 unchanged lines hidden (view full) ---

1091 /* Find the currently set OPP if we don't know already */
1092 if (unlikely(!opp_table->current_opp))
1093 _find_current_opp(dev, opp_table);
1094
1095 old_opp = opp_table->current_opp;
1096
1097 /* Return early if nothing to do */
1098 if (!forced && old_opp == opp && opp_table->enabled) {
1094 dev_dbg(dev, "%s: OPPs are same, nothing to do\n", __func__);
1099 dev_dbg_ratelimited(dev, "%s: OPPs are same, nothing to do\n", __func__);
1095 return 0;
1096 }
1097
1098 dev_dbg(dev, "%s: switching OPP: Freq %lu -> %lu Hz, Level %u -> %u, Bw %u -> %u\n",
1099 __func__, old_opp->rates[0], opp->rates[0], old_opp->level,
1100 opp->level, old_opp->bandwidth ? old_opp->bandwidth[0].peak : 0,
1101 opp->bandwidth ? opp->bandwidth[0].peak : 0);
1102

--- 250 unchanged lines hidden (view full) ---

1353
1354 BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head);
1355 INIT_LIST_HEAD(&opp_table->opp_list);
1356 kref_init(&opp_table->kref);
1357
1358 return opp_table;
1359
1360remove_opp_dev:
1100 return 0;
1101 }
1102
1103 dev_dbg(dev, "%s: switching OPP: Freq %lu -> %lu Hz, Level %u -> %u, Bw %u -> %u\n",
1104 __func__, old_opp->rates[0], opp->rates[0], old_opp->level,
1105 opp->level, old_opp->bandwidth ? old_opp->bandwidth[0].peak : 0,
1106 opp->bandwidth ? opp->bandwidth[0].peak : 0);
1107

--- 250 unchanged lines hidden (view full) ---

1358
1359 BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head);
1360 INIT_LIST_HEAD(&opp_table->opp_list);
1361 kref_init(&opp_table->kref);
1362
1363 return opp_table;
1364
1365remove_opp_dev:
1366 _of_clear_opp_table(opp_table);
1361 _remove_opp_dev(opp_dev, opp_table);
1367 _remove_opp_dev(opp_dev, opp_table);
1368 mutex_destroy(&opp_table->genpd_virt_dev_lock);
1369 mutex_destroy(&opp_table->lock);
1362err:
1363 kfree(opp_table);
1364 return ERR_PTR(ret);
1365}
1366
1367void _get_opp_table_kref(struct opp_table *opp_table)
1368{
1369 kref_get(&opp_table->kref);

--- 147 unchanged lines hidden (view full) ---

1517 if (opp_table->paths) {
1518 for (i = 0; i < opp_table->path_count; i++)
1519 icc_put(opp_table->paths[i]);
1520 kfree(opp_table->paths);
1521 }
1522
1523 WARN_ON(!list_empty(&opp_table->opp_list));
1524
1370err:
1371 kfree(opp_table);
1372 return ERR_PTR(ret);
1373}
1374
1375void _get_opp_table_kref(struct opp_table *opp_table)
1376{
1377 kref_get(&opp_table->kref);

--- 147 unchanged lines hidden (view full) ---

1525 if (opp_table->paths) {
1526 for (i = 0; i < opp_table->path_count; i++)
1527 icc_put(opp_table->paths[i]);
1528 kfree(opp_table->paths);
1529 }
1530
1531 WARN_ON(!list_empty(&opp_table->opp_list));
1532
1525 list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) {
1526 /*
1527 * The OPP table is getting removed, drop the performance state
1528 * constraints.
1529 */
1530 if (opp_table->genpd_performance_state)
1531 dev_pm_genpd_set_performance_state((struct device *)(opp_dev->dev), 0);
1532
1533 list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node)
1533 _remove_opp_dev(opp_dev, opp_table);
1534 _remove_opp_dev(opp_dev, opp_table);
1534 }
1535
1536 mutex_destroy(&opp_table->genpd_virt_dev_lock);
1537 mutex_destroy(&opp_table->lock);
1538 kfree(opp_table);
1539}
1540
1541void dev_pm_opp_put_opp_table(struct opp_table *opp_table)
1542{

--- 1156 unchanged lines hidden (view full) ---

2699 * point to one of the OPPs in the dst_table, but in some cases the
2700 * genpd and its master have one to one mapping of performance states
2701 * and so none of them have the "required-opps" property set. Return the
2702 * pstate of the src_table as it is in such cases.
2703 */
2704 if (!src_table || !src_table->required_opp_count)
2705 return pstate;
2706
1535
1536 mutex_destroy(&opp_table->genpd_virt_dev_lock);
1537 mutex_destroy(&opp_table->lock);
1538 kfree(opp_table);
1539}
1540
1541void dev_pm_opp_put_opp_table(struct opp_table *opp_table)
1542{

--- 1156 unchanged lines hidden (view full) ---

2699 * point to one of the OPPs in the dst_table, but in some cases the
2700 * genpd and its master have one to one mapping of performance states
2701 * and so none of them have the "required-opps" property set. Return the
2702 * pstate of the src_table as it is in such cases.
2703 */
2704 if (!src_table || !src_table->required_opp_count)
2705 return pstate;
2706
2707 /* Both OPP tables must belong to genpds */
2708 if (unlikely(!src_table->is_genpd || !dst_table->is_genpd)) {
2709 pr_err("%s: Performance state is only valid for genpds.\n", __func__);
2710 return -EINVAL;
2711 }
2712
2707 /* required-opps not fully initialized yet */
2708 if (lazy_linking_pending(src_table))
2709 return -EBUSY;
2710
2711 for (i = 0; i < src_table->required_opp_count; i++) {
2712 if (src_table->required_opp_tables[i]->np == dst_table->np)
2713 break;
2714 }

--- 376 unchanged lines hidden ---
2713 /* required-opps not fully initialized yet */
2714 if (lazy_linking_pending(src_table))
2715 return -EBUSY;
2716
2717 for (i = 0; i < src_table->required_opp_count; i++) {
2718 if (src_table->required_opp_tables[i]->np == dst_table->np)
2719 break;
2720 }

--- 376 unchanged lines hidden ---