PM: EM: Force device drivers to provide power in uW
authorLukasz Luba <lukasz.luba@arm.com>
Fri, 8 Mar 2024 12:32:03 +0000 (12:32 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 13 Mar 2024 19:48:38 +0000 (20:48 +0100)
The EM only supports power in uW. Make sure that it is not possible to
register some downstream driver which doesn't provide power in uW.
The only exception is artificial EM, but that EM is ignored by the rest of
kernel frameworks (thermal, powercap, etc).

Reported-by: PoShao Chen <poshao.chen@mediatek.com>
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/energy_model.c

index b686ac0..9e1c9aa 100644 (file)
@@ -612,6 +612,17 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
        else if (cb->get_cost)
                flags |= EM_PERF_DOMAIN_ARTIFICIAL;
 
+       /*
+        * EM only supports uW (exception is artificial EM).
+        * Therefore, check and force the drivers to provide
+        * power in uW.
+        */
+       if (!microwatts && !(flags & EM_PERF_DOMAIN_ARTIFICIAL)) {
+               dev_err(dev, "EM: only supports uW power values\n");
+               ret = -EINVAL;
+               goto unlock;
+       }
+
        ret = em_create_pd(dev, nr_states, cb, cpus, flags);
        if (ret)
                goto unlock;