An error occurred fetching the project authors.
  1. 27 Oct, 2020 1 commit
  2. 16 Sep, 2020 3 commits
  3. 25 Aug, 2020 1 commit
    • Stephan Gerhold's avatar
      opp: Allow dev_pm_opp_get_opp_table() to return -EPROBE_DEFER · dd461cd9
      Stephan Gerhold authored
      The OPP core manages various resources, e.g. clocks or interconnect paths.
      These resources are looked up when the OPP table is allocated once
      dev_pm_opp_get_opp_table() is called the first time (either directly
      or indirectly through one of the many helper functions).
      
      At this point, the resources may not be available yet, i.e. looking them
      up will result in -EPROBE_DEFER. Unfortunately, dev_pm_opp_get_opp_table()
      is currently unable to propagate this error code since it only returns
      the allocated OPP table or NULL.
      
      This means that all consumers of the OPP core are required to make sure
      that all necessary resources are available. Usually this happens by
      requesting them, checking the result and releasing them immediately after.
      
      For example, we have added "dev_pm_opp_of_find_icc_paths(dev, NULL)" to
      several drivers now just to make sure the interconnect providers are
      ready before the OPP table is allocated. If this call is missing,
      the OPP core will only warn about this and then attempt to continue
      without interconnect. This will eventually fail horribly, e.g.:
      
          cpu cpu0: _allocate_opp_table: Error finding interconnect paths: -517
          ... later ...
          of: _read_bw: Mismatch between opp-peak-kBps and paths (1 0)
          cpu cpu0: _opp_add_static_v2: opp key field not found
          cpu cpu0: _of_add_opp_table_v2: Failed to add OPP, -22
      
      This example happens when trying to use interconnects for a CPU OPP
      table together with qcom-cpufreq-nvmem.c. qcom-cpufreq-nvmem calls
      dev_pm_opp_set_supported_hw(), which ends up allocating the OPP table
      early. To fix the problem with the current approach we would need to add
      yet another call to dev_pm_opp_of_find_icc_paths(dev, NULL).
      But actually qcom-cpufreq-nvmem.c has nothing to do with interconnects...
      
      This commit attempts to make this more robust by allowing
      dev_pm_opp_get_opp_table() to return an error pointer. Fixing all
      the usages is trivial because the function is usually used indirectly
      through another helper (e.g. dev_pm_opp_set_supported_hw() above).
      These other helpers already return an error pointer.
      
      The example above then works correctly because set_supported_hw() will
      return -EPROBE_DEFER, and qcom-cpufreq-nvmem.c already propagates that
      error. It should also be possible to remove the remaining usages of
      "dev_pm_opp_of_find_icc_paths(dev, NULL)" from other drivers as well.
      
      Note that this commit currently only handles -EPROBE_DEFER for the
      clock/interconnects within _allocate_opp_table(). Other errors are just
      ignored as before. Eventually those should be propagated as well.
      Signed-off-by: default avatarStephan Gerhold <stephan@gerhold.net>
      Acked-by: default avatarKrzysztof Kozlowski <krzk@kernel.org>
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      [ Viresh: skip checking return value of dev_pm_opp_get_opp_table() for
      	  EPROBE_DEFER in domain.c, fix NULL return value and reorder
      	  code a bit in core.c, and update exynos-asv.c ]
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      dd461cd9
  4. 24 Aug, 2020 1 commit
  5. 16 Jul, 2020 1 commit
    • Walter Lozano's avatar
      opp: Increase parsed_static_opps in _of_add_opp_table_v1() · 6544abc5
      Walter Lozano authored
      Currently, when using _of_add_opp_table_v2 parsed_static_opps is
      increased and this value is used in _opp_remove_all_static() to
      check if there are static opp entries that need to be freed.
      Unfortunately this does not happen when using _of_add_opp_table_v1(),
      which leads to warnings.
      
      This patch increases parsed_static_opps in _of_add_opp_table_v1() in a
      similar way as in _of_add_opp_table_v2().
      
      Fixes: 03758d60 ("opp: Replace list_kref with a local counter")
      Cc: v5.6+ <stable@vger.kernel.org> # v5.6+
      Signed-off-by: default avatarWalter Lozano <walter.lozano@collabora.com>
      [ Viresh: Do the operation with lock held and set the value to 1 instead
      	  of incrementing it ]
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      6544abc5
  6. 24 Jun, 2020 2 commits
  7. 01 Jun, 2020 1 commit
  8. 29 May, 2020 2 commits
  9. 13 May, 2020 1 commit
  10. 10 Dec, 2019 2 commits
    • Viresh Kumar's avatar
      opp: Replace list_kref with a local counter · 03758d60
      Viresh Kumar authored
      A kref or refcount isn't the right tool to be used here for counting
      number of devices that are sharing the static OPPs created for the OPP
      table. For example, we are reinitializing the kref again, after it
      reaches a value of 0 and frees the resources, if the static OPPs get
      added for the same OPP table structure (as the OPP table structure was
      never freed). That is messy and very unclear.
      
      This patch makes parsed_static_opps an unsigned integer and uses it to
      count the number of users of the static OPPs. The increment and
      decrement to parsed_static_opps is done under opp_table->lock now to
      make sure no races are possible if the OPP table is getting added and
      removed in parallel (which doesn't happen in practice, but can in
      theory).
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      03758d60
    • Viresh Kumar's avatar
      opp: Free static OPPs on errors while adding them · ba003319
      Viresh Kumar authored
      The static OPPs aren't getting freed properly, if errors occur while
      adding them. Fix that by calling _put_opp_list_kref() and putting their
      reference on failures.
      
      Fixes: 11e1a164 ("opp: Don't decrement uninitialized list_kref")
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      ba003319
  11. 23 Oct, 2019 1 commit
  12. 10 Oct, 2019 1 commit
  13. 26 Jul, 2019 2 commits
    • Anson Huang's avatar
      opp: of: Support multiple suspend OPPs defined in DT · 45275517
      Anson Huang authored
      With property "opp-supported-hw" introduced, the OPP table
      in DT could be a large OPP table and ONLY a subset of OPPs
      are available, based on the version of the hardware running
      on. That introduces restriction of using "opp-suspend"
      property to define the suspend OPP, as we are NOT sure if the
      OPP containing "opp-suspend" property is available for the
      hardware running on, and the of opp core does NOT allow multiple
      suspend OPPs defined in DT OPP table.
      
      To eliminate this restrition, make of opp core allow multiple
      suspend OPPs defined in DT, and pick the OPP with highest rate
      and with "opp-suspend" property present to be suspend OPP, it
      can speed up the suspend/resume process.
      Signed-off-by: default avatarAnson Huang <Anson.Huang@nxp.com>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      45275517
    • Viresh Kumar's avatar
      opp: Don't decrement uninitialized list_kref · 11e1a164
      Viresh Kumar authored
      The list_kref was added for static OPPs and to track their users. The
      kref is initialized while the static OPPs are added, but removed
      unconditionally even if the static OPPs were never added. This causes
      refcount mismatch warnings currently.
      
      Fix that by always initializing the kref when the OPP table is first
      initialized. The refcount is later incremented only for the second user
      onwards.
      
      Fixes: d0e8ae6c ("OPP: Create separate kref for static OPPs list")
      Reported-by: default avatarRajendra Nayak <rnayak@codeaurora.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      11e1a164
  14. 19 Jun, 2019 1 commit
  15. 20 May, 2019 1 commit
    • Viresh Kumar's avatar
      opp: Allocate genpd_virt_devs from dev_pm_opp_attach_genpd() · c0ab9e08
      Viresh Kumar authored
      Currently the space for the array of virtual devices is allocated along
      with the OPP table, but that isn't going to work well from now onwards.
      For single power domain case, a driver can either use the original
      device structure for setting the performance state (if genpd attached
      with dev_pm_domain_attach()) or use the virtual device structure (if
      genpd attached with dev_pm_domain_attach_by_name(), which returns the
      virtual device) and so we can't know in advance if we are going to need
      genpd_virt_devs array or not.
      
      Lets delay the allocation a bit and do it along with
      dev_pm_opp_attach_genpd() rather. The deallocation is done from
      dev_pm_opp_detach_genpd().
      Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      c0ab9e08
  16. 11 Mar, 2019 1 commit
  17. 07 Feb, 2019 1 commit
    • Quentin Perret's avatar
      PM / OPP: Introduce a power estimation helper · a4f342b9
      Quentin Perret authored
      The Energy Model (EM) framework provides an API to let drivers register
      the active power of CPUs. The drivers are expected to provide a callback
      method which estimates the power consumed by a CPU at each available
      performance levels. How exactly this should be implemented, however,
      depends on the platform.
      
      On some systems, PM_OPP knows the voltage and frequency at which CPUs
      can run. When coupled with the CPU 'capacitance' (as provided by the
      'dynamic-power-coefficient' devicetree binding), it is possible to
      estimate the dynamic power consumption of a CPU as P = C * V^2 * f, with
      C its capacitance and V and f respectively the voltage and frequency of
      the OPP. The Intelligent Power Allocator (IPA) thermal governor already
      implements that estimation method, in the thermal framework.
      
      However, this power estimation method can be applied to any platform
      where all the parameters are known (C, V and f), and not only those
      suffering thermal issues. As such, the code implementing this feature
      can be re-used to also populate the EM framework now used by EAS.
      
      As a first step, introduce in PM_OPP a helper function which CPUFreq
      drivers can use to register into the EM framework. This duplicates the
      power estimation done in IPA until it can be migrated to using the EM
      framework. This will be done later, once the EM framework has support
      for at least all platforms currently supported by IPA.
      Signed-off-by: default avatarQuentin Perret <quentin.perret@arm.com>
      Tested-by: default avatarMatthias Kaehlcke <mka@chromium.org>
      Reviewed-by: default avatarMatthias Kaehlcke <mka@chromium.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      a4f342b9
  18. 22 Jan, 2019 1 commit
  19. 14 Dec, 2018 2 commits
  20. 11 Dec, 2018 1 commit
    • Viresh Kumar's avatar
      OPP: Fix missing debugfs supply directory for OPPs · 46f48aca
      Viresh Kumar authored
      There is one case where we may end up with no "supply" directory for the
      OPPs in debugfs. That happens when the OPP core isn't managing the
      regulators for the device and the device's OPP do have microvolt
      property. It happens because the opp_table->regulator_count remains set
      to 0 and the debugfs routines don't add any supply directory in such a
      case.
      
      This commit fixes that by setting opp_table->regulator_count to 1 in
      that particular case. But to make everything work nicely and not break
      other parts of the core, regulator_count is defined as "int" now instead
      of "unsigned int" and it can have different special values now. It is
      set to -1 initially to mark it "uninitialized" and later only we set it
      to 0 or positive values after checking how many supplies are there.
      
      This also helps in finding the bugs where only few of the OPPs have the
      "opp-microvolt" property set and not all.
      
      Fixes: 1fae788e ("PM / OPP: Don't create debugfs "supply-0" directory unnecessarily")
      Reported-by: default avatarQuentin Perret <quentin.perret@arm.com>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      46f48aca
  21. 23 Nov, 2018 1 commit
  22. 05 Nov, 2018 7 commits
    • Viresh Kumar's avatar
      OPP: Remove of_dev_pm_opp_find_required_opp() · 534245cc
      Viresh Kumar authored
      This isn't used anymore, remove it.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      534245cc
    • Viresh Kumar's avatar
      OPP: Rename and relocate of_genpd_opp_to_performance_state() · 4c6a343e
      Viresh Kumar authored
      The OPP core already has the performance state values for each of the
      genpd's OPPs and there is no need to call the genpd callback again to
      get the performance state for the case where the end device doesn't have
      an OPP table and has the "required-opps" property directly in its node.
      
      This commit renames of_genpd_opp_to_performance_state() as
      of_get_required_opp_performance_state() and moves it to the OPP core, as
      it is all about OPP stuff now.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      4c6a343e
    • Viresh Kumar's avatar
      OPP: Configure all required OPPs · ca1b5d77
      Viresh Kumar authored
      Now that all the infrastructure is in place to support multiple required
      OPPs, lets switch over to using it.
      
      A new internal routine _set_required_opps() takes care of updating
      performance state for all the required OPPs. With this the performance
      state updates are supported even when the end device needs to configure
      regulators as well, that wasn't the case earlier.
      
      The pstates were earlier stored in the end device's OPP structures, that
      also changes now as those values are stored in the genpd's OPP
      structures. And so we switch over to using
      pm_genpd_opp_to_performance_state() instead of
      of_genpd_opp_to_performance_state() to get performance state for the
      genpd OPPs.
      
      The routine _generic_set_opp_domain() is not required anymore and is
      removed.
      
      On errors we don't try to recover by reverting to old settings as things
      are really complex now and the calls here should never really fail
      unless there is a bug. There is no point increasing the complexity, for
      code which will never be executed.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      ca1b5d77
    • Viresh Kumar's avatar
      OPP: Add dev_pm_opp_{set|put}_genpd_virt_dev() helper · 4f018bc0
      Viresh Kumar authored
      Multiple generic power domains for a consumer device are supported with
      the help of virtual devices, which are created for each consumer device
      - genpd pair. These are the device structures which are attached to the
      power domain and are required by the OPP core to set the performance
      state of the genpd.
      
      The helpers added by this commit are required to be called once for each
      of these virtual devices. These are required only if multiple domains
      are available for a device, otherwise the actual device structure will
      be used instead by the OPP core.
      
      The new helpers also support the complex cases where the consumer device
      wouldn't always require all the domains. For example, a camera may
      require only one power domain during normal operations but two during
      high resolution operations. The consumer driver can call
      dev_pm_opp_put_genpd_virt_dev(high_resolution_genpd_virt_dev) if it is
      currently operating in the normal mode and doesn't have any performance
      requirements from the genpd which manages high resolution power
      requirements. The consumer driver can later call
      dev_pm_opp_set_genpd_virt_dev(high_resolution_genpd_virt_dev) once it
      switches back to the high resolution mode.
      
      The new helpers differ from other OPP set/put helpers as the new ones
      can be called with OPPs initialized for the table as we may need to call
      them on the fly because of the complex case explained above. For this
      reason it is possible that the genpd virt_dev structure may be used in
      parallel while the new helpers are running and a new mutex is added to
      protect against that. We didn't use the existing opp_table->lock mutex
      as that is widely used in the OPP core and we will need this lock in the
      dev_pm_opp_set_rate() helper while changing OPP and we need to make sure
      there is not much contention while doing that as that's the hotpath.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      4f018bc0
    • Viresh Kumar's avatar
      OPP: Populate OPPs from "required-opps" property · da544b61
      Viresh Kumar authored
      An earlier commit populated the OPP tables from the "required-opps"
      property, this commit populates the individual OPPs. This is repeated
      for each OPP in the OPP table and these populated OPPs will be used by
      later commits.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      da544b61
    • Viresh Kumar's avatar
      OPP: Populate required opp tables from "required-opps" property · 5d6d106f
      Viresh Kumar authored
      The current implementation works only for the case where a single
      phandle is present in the "required-opps" property, while DT allows
      multiple phandles to be present there.
      
      This patch adds new infrastructure to parse all the phandles present in
      "required-opps" property and save pointers of the required OPP's OPP
      tables. These will be used by later commits.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      5d6d106f
    • Viresh Kumar's avatar
      OPP: Identify and mark genpd OPP tables · 61d8e7c7
      Viresh Kumar authored
      We need to handle genpd OPP tables differently, this is already the case
      at one location and will be extended going forward. Add another field to
      the OPP table to check if the table belongs to a genpd or not.
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      61d8e7c7
  23. 04 Oct, 2018 2 commits
    • Dave Gerlach's avatar
      PM / OPP: _of_add_opp_table_v2(): increment count only if OPP is added · deac8703
      Dave Gerlach authored
      Currently the _of_add_opp_table_v2 call loops through the OPP nodes in
      the operating-points-v2 table in the device tree and calls
      _opp_add_static_v2 for each to add them to the table. It counts each
      iteration through this loop as an added OPP, however there are cases
      where _opp_add_static_v2() returns 0 but no new OPP is added to the
      list.
      
      This can happen while adding duplicate OPP or if the OPP isn't supported
      by hardware.
      
      Because of this the count variable will contain the number of OPP nodes
      in the table in device tree but not necessarily the ones that are
      actually added.
      
      As this count value is what is checked to determine if there are any
      valid OPPs, if a platform has an operating-points-v2 table with all OPP
      nodes containing opp-supported-hw values that are not currently
      supported, then _of_add_opp_table_v2 will fail to abort as it should due
      to an empty table.
      
      Additionally, since commit 3ba98324 ("PM / OPP: Get
      performance state using genpd helper"), the same count variable is
      compared against the number of OPPs containing performance states and
      requires that either all or none have pstates set, however in the case
      of any opp table that has any entries that do not get added by
      _opp_add_static_v2 due to incompatible opp-supported-hw fields, these
      numbers will not match and _of_add_opp_table_v2 will incorrectly fail.
      
      We need to clearly identify all the three cases (success, failure,
      unsupported/duplicate OPPs) and then increment count only on success
      case. Change return type of _opp_add_static_v2() to return the pointer
      to the newly added OPP instead of an integer. This routine now returns a
      valid pointer if the OPP is really added, NULL for unsupported or
      duplicate OPPs, and error value cased as a pointer on errors.
      
      Ideally the fixes tag in this commit should point back to the commit
      that introduced OPP v2 initially, as that's where we started incorrectly
      accounting for duplicate OPPs:
      
      commit 27465902 ("PM / OPP: Add support to parse "operating-points-v2" bindings")
      
      But it wasn't a real problem until recently as the count was only used
      to check if any OPPs are added or not. And so this commit points to a
      rather recent commit where we added more code that depends on the value
      of "count".
      
      Fixes: 3ba98324 ("PM / OPP: Get performance state using genpd helper")
      Reported-by: default avatarDave Gerlach <d-gerlach@ti.com>
      Reported-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
      Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
      Signed-off-by: default avatarDave Gerlach <d-gerlach@ti.com>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      deac8703
    • Viresh Kumar's avatar
      OPP: Improve error handling in dev_pm_opp_of_cpumask_add_table() · 50b6b87c
      Viresh Kumar authored
      The error handling wasn't appropriate in
      dev_pm_opp_of_cpumask_add_table(). For example it returns 0 on success
      and also for the case where cpumask is empty or cpu_device wasn't found
      for any of the CPUs.
      
      It should really return error on such cases, so that the callers can be
      aware of the outcome.
      
      Fix it.
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      50b6b87c
  24. 01 Oct, 2018 2 commits
    • Viresh Kumar's avatar
      OPP: Pass OPP table to _of_add_opp_table_v{1|2}() · 5ed4cecd
      Viresh Kumar authored
      Both _of_add_opp_table_v1() and _of_add_opp_table_v2() contain similar
      code to get the OPP table and their parent routine also parses the DT to
      find the OPP table's node pointer. This can be simplified by getting the
      OPP table in advance and then passing it as argument to these routines.
      Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      5ed4cecd
    • Viresh Kumar's avatar
      OPP: Prevent creating multiple OPP tables for devices sharing OPP nodes · 283d55e6
      Viresh Kumar authored
      When two or more devices are sharing their clock and voltage rails, they
      share the same OPP table. But there are some corner cases where the OPP
      core incorrectly creates separate OPP tables for them.
      
      For example, CPU 0 and 1 share clock/voltage rails. The platform
      specific code calls dev_pm_opp_set_regulators() for CPU0 and the OPP
      core creates an OPP table for it (the individual OPPs aren't initialized
      as of now). The same is repeated for CPU1 then. Because
      _opp_get_opp_table() doesn't compare DT node pointers currently, it
      fails to find the link between CPU0 and CPU1 and so creates a new OPP
      table.
      
      Fix this by calling _managed_opp() from _opp_get_opp_table().
      _managed_opp() gain an additional argument (index) to get the right node
      pointer. This resulted in simplifying code in _of_add_opp_table_v2() as
      well.
      Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      283d55e6
  25. 19 Sep, 2018 1 commit
    • Viresh Kumar's avatar
      OPP: Use a single mechanism to free the OPP table · cdd6ed90
      Viresh Kumar authored
      Currently there are two separate ways to free the OPP table based on how
      it is created in the first place.
      
      We call _dev_pm_opp_remove_table() to free the static and/or dynamic
      OPP, OPP list devices, etc. This is done for the case where the OPP
      table is added while initializing the OPPs, like via the path
      dev_pm_opp_of_add_table().
      
      We also call dev_pm_opp_put_opp_table() in some cases which eventually
      frees the OPP table structure once the reference count reaches 0. This
      is used by the first case as well as other cases like
      dev_pm_opp_set_regulators() where the OPPs aren't necessarily
      initialized at this point.
      
      This whole thing is a bit unclear and messy and obstruct any further
      cleanup/fixup of OPP core.
      
      This patch tries to streamline this by keeping a single path for OPP
      table destruction, i.e. dev_pm_opp_put_opp_table().
      
      All the cleanup happens in _opp_table_kref_release() now after the
      reference count reaches 0. _dev_pm_opp_remove_table() is removed as it
      isn't required anymore.
      
      We don't drop the reference to the OPP table after creating it from
      _of_add_opp_table_v{1|2}() anymore and the same is dropped only when we
      try to remove them.
      Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
      Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      cdd6ed90