diff options
| -rw-r--r-- | drivers/base/power/opp.c | 127 |
1 files changed, 114 insertions, 13 deletions
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index f4aa85a72d36..1d20e095569c 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c | |||
| @@ -123,7 +123,7 @@ do { \ | |||
| 123 | * Search list of device OPPs for one containing matching device. Does a RCU | 123 | * Search list of device OPPs for one containing matching device. Does a RCU |
| 124 | * reader operation to grab the pointer needed. | 124 | * reader operation to grab the pointer needed. |
| 125 | * | 125 | * |
| 126 | * Returns pointer to 'struct device_opp' if found, otherwise -ENODEV or | 126 | * Return: pointer to 'struct device_opp' if found, otherwise -ENODEV or |
| 127 | * -EINVAL based on type of error. | 127 | * -EINVAL based on type of error. |
| 128 | * | 128 | * |
| 129 | * Locking: This function must be called under rcu_read_lock(). device_opp | 129 | * Locking: This function must be called under rcu_read_lock(). device_opp |
| @@ -153,7 +153,7 @@ static struct device_opp *_find_device_opp(struct device *dev) | |||
| 153 | * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an available opp | 153 | * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an available opp |
| 154 | * @opp: opp for which voltage has to be returned for | 154 | * @opp: opp for which voltage has to be returned for |
| 155 | * | 155 | * |
| 156 | * Return voltage in micro volt corresponding to the opp, else | 156 | * Return: voltage in micro volt corresponding to the opp, else |
| 157 | * return 0 | 157 | * return 0 |
| 158 | * | 158 | * |
| 159 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu | 159 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| @@ -183,7 +183,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_voltage); | |||
| 183 | * dev_pm_opp_get_freq() - Gets the frequency corresponding to an available opp | 183 | * dev_pm_opp_get_freq() - Gets the frequency corresponding to an available opp |
| 184 | * @opp: opp for which frequency has to be returned for | 184 | * @opp: opp for which frequency has to be returned for |
| 185 | * | 185 | * |
| 186 | * Return frequency in hertz corresponding to the opp, else | 186 | * Return: frequency in hertz corresponding to the opp, else |
| 187 | * return 0 | 187 | * return 0 |
| 188 | * | 188 | * |
| 189 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu | 189 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| @@ -213,7 +213,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq); | |||
| 213 | * dev_pm_opp_get_opp_count() - Get number of opps available in the opp list | 213 | * dev_pm_opp_get_opp_count() - Get number of opps available in the opp list |
| 214 | * @dev: device for which we do this operation | 214 | * @dev: device for which we do this operation |
| 215 | * | 215 | * |
| 216 | * This function returns the number of available opps if there are any, | 216 | * Return: This function returns the number of available opps if there are any, |
| 217 | * else returns 0 if none or the corresponding error value. | 217 | * else returns 0 if none or the corresponding error value. |
| 218 | * | 218 | * |
| 219 | * Locking: This function takes rcu_read_lock(). | 219 | * Locking: This function takes rcu_read_lock(). |
| @@ -251,9 +251,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); | |||
| 251 | * @freq: frequency to search for | 251 | * @freq: frequency to search for |
| 252 | * @available: true/false - match for available opp | 252 | * @available: true/false - match for available opp |
| 253 | * | 253 | * |
| 254 | * Searches for exact match in the opp list and returns pointer to the matching | 254 | * Return: Searches for exact match in the opp list and returns pointer to the |
| 255 | * opp if found, else returns ERR_PTR in case of error and should be handled | 255 | * matching opp if found, else returns ERR_PTR in case of error and should |
| 256 | * using IS_ERR. Error return values can be: | 256 | * be handled using IS_ERR. Error return values can be: |
| 257 | * EINVAL: for bad pointer | 257 | * EINVAL: for bad pointer |
| 258 | * ERANGE: no match found for search | 258 | * ERANGE: no match found for search |
| 259 | * ENODEV: if device not found in list of registered devices | 259 | * ENODEV: if device not found in list of registered devices |
| @@ -307,7 +307,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact); | |||
| 307 | * Search for the matching ceil *available* OPP from a starting freq | 307 | * Search for the matching ceil *available* OPP from a starting freq |
| 308 | * for a device. | 308 | * for a device. |
| 309 | * | 309 | * |
| 310 | * Returns matching *opp and refreshes *freq accordingly, else returns | 310 | * Return: matching *opp and refreshes *freq accordingly, else returns |
| 311 | * ERR_PTR in case of error and should be handled using IS_ERR. Error return | 311 | * ERR_PTR in case of error and should be handled using IS_ERR. Error return |
| 312 | * values can be: | 312 | * values can be: |
| 313 | * EINVAL: for bad pointer | 313 | * EINVAL: for bad pointer |
| @@ -357,7 +357,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); | |||
| 357 | * Search for the matching floor *available* OPP from a starting freq | 357 | * Search for the matching floor *available* OPP from a starting freq |
| 358 | * for a device. | 358 | * for a device. |
| 359 | * | 359 | * |
| 360 | * Returns matching *opp and refreshes *freq accordingly, else returns | 360 | * Return: matching *opp and refreshes *freq accordingly, else returns |
| 361 | * ERR_PTR in case of error and should be handled using IS_ERR. Error return | 361 | * ERR_PTR in case of error and should be handled using IS_ERR. Error return |
| 362 | * values can be: | 362 | * values can be: |
| 363 | * EINVAL: for bad pointer | 363 | * EINVAL: for bad pointer |
| @@ -403,6 +403,15 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, | |||
| 403 | } | 403 | } |
| 404 | EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); | 404 | EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); |
| 405 | 405 | ||
| 406 | /** | ||
| 407 | * _add_device_opp() - Allocate a new device OPP table | ||
| 408 | * @dev: device for which we do this operation | ||
| 409 | * | ||
| 410 | * New device node which uses OPPs - used when multiple devices with OPP tables | ||
| 411 | * are maintained. | ||
| 412 | * | ||
| 413 | * Return: valid device_opp pointer if success, else NULL. | ||
| 414 | */ | ||
| 406 | static struct device_opp *_add_device_opp(struct device *dev) | 415 | static struct device_opp *_add_device_opp(struct device *dev) |
| 407 | { | 416 | { |
| 408 | struct device_opp *dev_opp; | 417 | struct device_opp *dev_opp; |
| @@ -424,6 +433,33 @@ static struct device_opp *_add_device_opp(struct device *dev) | |||
| 424 | return dev_opp; | 433 | return dev_opp; |
| 425 | } | 434 | } |
| 426 | 435 | ||
| 436 | /** | ||
| 437 | * _opp_add_dynamic() - Allocate a dynamic OPP. | ||
| 438 | * @dev: device for which we do this operation | ||
| 439 | * @freq: Frequency in Hz for this OPP | ||
| 440 | * @u_volt: Voltage in uVolts for this OPP | ||
| 441 | * @dynamic: Dynamically added OPPs. | ||
| 442 | * | ||
| 443 | * This function adds an opp definition to the opp list and returns status. | ||
| 444 | * The opp is made available by default and it can be controlled using | ||
| 445 | * dev_pm_opp_enable/disable functions and may be removed by dev_pm_opp_remove. | ||
| 446 | * | ||
| 447 | * NOTE: "dynamic" parameter impacts OPPs added by the of_init_opp_table and | ||
| 448 | * freed by of_free_opp_table. | ||
| 449 | * | ||
| 450 | * Locking: The internal device_opp and opp structures are RCU protected. | ||
| 451 | * Hence this function internally uses RCU updater strategy with mutex locks | ||
| 452 | * to keep the integrity of the internal data structures. Callers should ensure | ||
| 453 | * that this function is *NOT* called under RCU protection or in contexts where | ||
| 454 | * mutex cannot be locked. | ||
| 455 | * | ||
| 456 | * Return: | ||
| 457 | * 0 On success OR | ||
| 458 | * Duplicate OPPs (both freq and volt are same) and opp->available | ||
| 459 | * -EEXIST Freq are same and volt are different OR | ||
| 460 | * Duplicate OPPs (both freq and volt are same) and !opp->available | ||
| 461 | * -ENOMEM Memory allocation failure | ||
| 462 | */ | ||
| 427 | static int _opp_add_dynamic(struct device *dev, unsigned long freq, | 463 | static int _opp_add_dynamic(struct device *dev, unsigned long freq, |
| 428 | long u_volt, bool dynamic) | 464 | long u_volt, bool dynamic) |
| 429 | { | 465 | { |
| @@ -519,11 +555,11 @@ free_opp: | |||
| 519 | * mutex cannot be locked. | 555 | * mutex cannot be locked. |
| 520 | * | 556 | * |
| 521 | * Return: | 557 | * Return: |
| 522 | * 0: On success OR | 558 | * 0 On success OR |
| 523 | * Duplicate OPPs (both freq and volt are same) and opp->available | 559 | * Duplicate OPPs (both freq and volt are same) and opp->available |
| 524 | * -EEXIST: Freq are same and volt are different OR | 560 | * -EEXIST Freq are same and volt are different OR |
| 525 | * Duplicate OPPs (both freq and volt are same) and !opp->available | 561 | * Duplicate OPPs (both freq and volt are same) and !opp->available |
| 526 | * -ENOMEM: Memory allocation failure | 562 | * -ENOMEM Memory allocation failure |
| 527 | */ | 563 | */ |
| 528 | int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) | 564 | int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) |
| 529 | { | 565 | { |
| @@ -531,6 +567,10 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) | |||
| 531 | } | 567 | } |
| 532 | EXPORT_SYMBOL_GPL(dev_pm_opp_add); | 568 | EXPORT_SYMBOL_GPL(dev_pm_opp_add); |
| 533 | 569 | ||
| 570 | /** | ||
| 571 | * _kfree_opp_rcu() - Free OPP RCU handler | ||
| 572 | * @head: RCU head | ||
| 573 | */ | ||
| 534 | static void _kfree_opp_rcu(struct rcu_head *head) | 574 | static void _kfree_opp_rcu(struct rcu_head *head) |
| 535 | { | 575 | { |
| 536 | struct dev_pm_opp *opp = container_of(head, struct dev_pm_opp, rcu_head); | 576 | struct dev_pm_opp *opp = container_of(head, struct dev_pm_opp, rcu_head); |
| @@ -538,6 +578,10 @@ static void _kfree_opp_rcu(struct rcu_head *head) | |||
| 538 | kfree_rcu(opp, rcu_head); | 578 | kfree_rcu(opp, rcu_head); |
| 539 | } | 579 | } |
| 540 | 580 | ||
| 581 | /** | ||
| 582 | * _kfree_device_rcu() - Free device_opp RCU handler | ||
| 583 | * @head: RCU head | ||
| 584 | */ | ||
| 541 | static void _kfree_device_rcu(struct rcu_head *head) | 585 | static void _kfree_device_rcu(struct rcu_head *head) |
| 542 | { | 586 | { |
| 543 | struct device_opp *device_opp = container_of(head, struct device_opp, rcu_head); | 587 | struct device_opp *device_opp = container_of(head, struct device_opp, rcu_head); |
| @@ -545,6 +589,17 @@ static void _kfree_device_rcu(struct rcu_head *head) | |||
| 545 | kfree_rcu(device_opp, rcu_head); | 589 | kfree_rcu(device_opp, rcu_head); |
| 546 | } | 590 | } |
| 547 | 591 | ||
| 592 | /** | ||
| 593 | * _opp_remove() - Remove an OPP from a table definition | ||
| 594 | * @dev_opp: points back to the device_opp struct this opp belongs to | ||
| 595 | * @opp: pointer to the OPP to remove | ||
| 596 | * | ||
| 597 | * This function removes an opp definition from the opp list. | ||
| 598 | * | ||
| 599 | * Locking: The internal device_opp and opp structures are RCU protected. | ||
| 600 | * It is assumed that the caller holds required mutex for an RCU updater | ||
| 601 | * strategy. | ||
| 602 | */ | ||
| 548 | static void _opp_remove(struct device_opp *dev_opp, | 603 | static void _opp_remove(struct device_opp *dev_opp, |
| 549 | struct dev_pm_opp *opp) | 604 | struct dev_pm_opp *opp) |
| 550 | { | 605 | { |
| @@ -569,6 +624,12 @@ static void _opp_remove(struct device_opp *dev_opp, | |||
| 569 | * @freq: OPP to remove with matching 'freq' | 624 | * @freq: OPP to remove with matching 'freq' |
| 570 | * | 625 | * |
| 571 | * This function removes an opp from the opp list. | 626 | * This function removes an opp from the opp list. |
| 627 | * | ||
| 628 | * Locking: The internal device_opp and opp structures are RCU protected. | ||
| 629 | * Hence this function internally uses RCU updater strategy with mutex locks | ||
| 630 | * to keep the integrity of the internal data structures. Callers should ensure | ||
| 631 | * that this function is *NOT* called under RCU protection or in contexts where | ||
| 632 | * mutex cannot be locked. | ||
| 572 | */ | 633 | */ |
| 573 | void dev_pm_opp_remove(struct device *dev, unsigned long freq) | 634 | void dev_pm_opp_remove(struct device *dev, unsigned long freq) |
| 574 | { | 635 | { |
| @@ -611,7 +672,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_remove); | |||
| 611 | * Set the availability of an OPP with an RCU operation, opp_{enable,disable} | 672 | * Set the availability of an OPP with an RCU operation, opp_{enable,disable} |
| 612 | * share a common logic which is isolated here. | 673 | * share a common logic which is isolated here. |
| 613 | * | 674 | * |
| 614 | * Returns -EINVAL for bad pointers, -ENOMEM if no memory available for the | 675 | * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the |
| 615 | * copy operation, returns 0 if no modifcation was done OR modification was | 676 | * copy operation, returns 0 if no modifcation was done OR modification was |
| 616 | * successful. | 677 | * successful. |
| 617 | * | 678 | * |
| @@ -700,6 +761,10 @@ unlock: | |||
| 700 | * integrity of the internal data structures. Callers should ensure that | 761 | * integrity of the internal data structures. Callers should ensure that |
| 701 | * this function is *NOT* called under RCU protection or in contexts where | 762 | * this function is *NOT* called under RCU protection or in contexts where |
| 702 | * mutex locking or synchronize_rcu() blocking calls cannot be used. | 763 | * mutex locking or synchronize_rcu() blocking calls cannot be used. |
| 764 | * | ||
| 765 | * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the | ||
| 766 | * copy operation, returns 0 if no modifcation was done OR modification was | ||
| 767 | * successful. | ||
| 703 | */ | 768 | */ |
| 704 | int dev_pm_opp_enable(struct device *dev, unsigned long freq) | 769 | int dev_pm_opp_enable(struct device *dev, unsigned long freq) |
| 705 | { | 770 | { |
| @@ -722,6 +787,10 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_enable); | |||
| 722 | * integrity of the internal data structures. Callers should ensure that | 787 | * integrity of the internal data structures. Callers should ensure that |
| 723 | * this function is *NOT* called under RCU protection or in contexts where | 788 | * this function is *NOT* called under RCU protection or in contexts where |
| 724 | * mutex locking or synchronize_rcu() blocking calls cannot be used. | 789 | * mutex locking or synchronize_rcu() blocking calls cannot be used. |
| 790 | * | ||
| 791 | * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the | ||
| 792 | * copy operation, returns 0 if no modifcation was done OR modification was | ||
| 793 | * successful. | ||
| 725 | */ | 794 | */ |
| 726 | int dev_pm_opp_disable(struct device *dev, unsigned long freq) | 795 | int dev_pm_opp_disable(struct device *dev, unsigned long freq) |
| 727 | { | 796 | { |
| @@ -732,6 +801,16 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_disable); | |||
| 732 | /** | 801 | /** |
| 733 | * dev_pm_opp_get_notifier() - find notifier_head of the device with opp | 802 | * dev_pm_opp_get_notifier() - find notifier_head of the device with opp |
| 734 | * @dev: device pointer used to lookup device OPPs. | 803 | * @dev: device pointer used to lookup device OPPs. |
| 804 | * | ||
| 805 | * Return: pointer to notifier head if found, otherwise -ENODEV or | ||
| 806 | * -EINVAL based on type of error casted as pointer. value must be checked | ||
| 807 | * with IS_ERR to determine valid pointer or error result. | ||
| 808 | * | ||
| 809 | * Locking: This function must be called under rcu_read_lock(). dev_opp is a RCU | ||
| 810 | * protected pointer. The reason for the same is that the opp pointer which is | ||
| 811 | * returned will remain valid for use with opp_get_{voltage, freq} only while | ||
| 812 | * under the locked area. The pointer returned must be used prior to unlocking | ||
| 813 | * with rcu_read_unlock() to maintain the integrity of the pointer. | ||
| 735 | */ | 814 | */ |
| 736 | struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev) | 815 | struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev) |
| 737 | { | 816 | { |
| @@ -750,6 +829,22 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier); | |||
| 750 | * @dev: device pointer used to lookup device OPPs. | 829 | * @dev: device pointer used to lookup device OPPs. |
| 751 | * | 830 | * |
| 752 | * Register the initial OPP table with the OPP library for given device. | 831 | * Register the initial OPP table with the OPP library for given device. |
| 832 | * | ||
| 833 | * Locking: The internal device_opp and opp structures are RCU protected. | ||
| 834 | * Hence this function indirectly uses RCU updater strategy with mutex locks | ||
| 835 | * to keep the integrity of the internal data structures. Callers should ensure | ||
| 836 | * that this function is *NOT* called under RCU protection or in contexts where | ||
| 837 | * mutex cannot be locked. | ||
| 838 | * | ||
| 839 | * Return: | ||
| 840 | * 0 On success OR | ||
| 841 | * Duplicate OPPs (both freq and volt are same) and opp->available | ||
| 842 | * -EEXIST Freq are same and volt are different OR | ||
| 843 | * Duplicate OPPs (both freq and volt are same) and !opp->available | ||
| 844 | * -ENOMEM Memory allocation failure | ||
| 845 | * -ENODEV when 'operating-points' property is not found or is invalid data | ||
| 846 | * in device node. | ||
| 847 | * -ENODATA when empty 'operating-points' property is found | ||
| 753 | */ | 848 | */ |
| 754 | int of_init_opp_table(struct device *dev) | 849 | int of_init_opp_table(struct device *dev) |
| 755 | { | 850 | { |
| @@ -793,6 +888,12 @@ EXPORT_SYMBOL_GPL(of_init_opp_table); | |||
| 793 | * @dev: device pointer used to lookup device OPPs. | 888 | * @dev: device pointer used to lookup device OPPs. |
| 794 | * | 889 | * |
| 795 | * Free OPPs created using static entries present in DT. | 890 | * Free OPPs created using static entries present in DT. |
| 891 | * | ||
| 892 | * Locking: The internal device_opp and opp structures are RCU protected. | ||
| 893 | * Hence this function indirectly uses RCU updater strategy with mutex locks | ||
| 894 | * to keep the integrity of the internal data structures. Callers should ensure | ||
| 895 | * that this function is *NOT* called under RCU protection or in contexts where | ||
| 896 | * mutex cannot be locked. | ||
| 796 | */ | 897 | */ |
| 797 | void of_free_opp_table(struct device *dev) | 898 | void of_free_opp_table(struct device *dev) |
| 798 | { | 899 | { |
