Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-02 Thread Zhang Rui
On Wed, 2020-07-01 at 11:50 +0200, Daniel Lezcano wrote:
> On 01/07/2020 09:57, Zhang Rui wrote:
> 
> [ ... ]
> 
> > > Do you want to move them out?
> > 
> > Then no. I don't have any objection of removing thermal_helper.c,
> > so
> > you can just leave these functions in thermal_core.c
> 
> Shall I consider that as an ack for this patch ?
> 
sure.

Acked-by: Zhang Rui 

thanks,
rui
> 



Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-01 Thread Daniel Lezcano
On 01/07/2020 11:26, Amit Kucheria wrote:
> On Wed, Jul 1, 2020 at 1:27 PM Zhang Rui  wrote:

[ ... ]

>> Then no. I don't have any objection of removing thermal_helper.c, so
>> you can just leave these functions in thermal_core.c
> 
> In that case, Daniel, please find attached a patch to move the
> contents of thermal_helpers into thermal_core.c
> 
> Feel free to include it at the top of this series and modify as you see fit.

I will keep it separate for the moment until this series is accepted and
then send a respin of this patch on top of the merged series.

Thanks

-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-01 Thread Daniel Lezcano
On 01/07/2020 09:57, Zhang Rui wrote:

[ ... ]

>> Do you want to move them out?
> 
> Then no. I don't have any objection of removing thermal_helper.c, so
> you can just leave these functions in thermal_core.c

Shall I consider that as an ack for this patch ?


-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-01 Thread Amit Kucheria
On Wed, Jul 1, 2020 at 1:27 PM Zhang Rui  wrote:
>
> On Wed, 2020-07-01 at 09:35 +0200, Daniel Lezcano wrote:
> > On 30/06/2020 17:09, Zhang Rui wrote:
> > > Hi, Daniel,
> > >
> > > seems that you forgot to cc linux-pm mailing list.
> > >
> > > On Tue, 2020-06-30 at 17:16 +0530, Amit Kucheria wrote:
> > > > On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
> > > >  wrote:
> > > > >
> > > > > The cdev, tz and governor list, as well as their respective
> > > > > locks
> > > > > are
> > > > > statically defined in the thermal_core.c file.
> > > > >
> > > > > In order to give a sane access to these list, like browsing all
> > > > > the
> > > > > thermal zones or all the cooling devices, let's define a set of
> > > > > helpers where we pass a callback as a parameter to be called
> > > > > for
> > > > > each
> > > > > thermal entity.
> > > > >
> > > > > We keep the self-encapsulation and ensure the locks are
> > > > > correctly
> > > > > taken when looking at the list.
> > > > >
> > > > > Signed-off-by: Daniel Lezcano 
> > > > > ---
> > > > >  drivers/thermal/thermal_core.c | 51
> > > > > ++
> > > >
> > > > Is the idea to not use thermal_helpers.c from now on? It fits
> > > > perfectly with a patch I have to merge all its contents to
> > > > thermal_core.c :-)
> > >
> > > I agree these changes should be in thermal_helper.c
> >
> > Oh, actually I remind put those functions in the thermal_core.c file
> > because they need the locks which are statically defined in there.
> >
> > If the functions are moved to thermal_helper.c that will imply to
> > export
> > the locks outside of the file, thus breaking the self-encapsulation.
> >
> > Do you want to move them out?
>
> Then no. I don't have any objection of removing thermal_helper.c, so
> you can just leave these functions in thermal_core.c

In that case, Daniel, please find attached a patch to move the
contents of thermal_helpers into thermal_core.c

Feel free to include it at the top of this series and modify as you see fit.

Regards,
Amit
From e09befc6c6717c3e4554b0688c7d83b0696d2554 Mon Sep 17 00:00:00 2001
Message-Id: 
From: Amit Kucheria 
Date: Wed, 1 Jul 2020 14:48:47 +0530
Subject: [PATCH] thermal/core: Merge thermal_helpers.c into thermal_core.c

Moving several helper functions to this file require unnecessarily
exposing locks outside thermal_core.c.

It is better to simply move the few functions in there directly into
thermal_core.c.

Signed-off-by: Amit Kucheria 
---
 drivers/thermal/Makefile  |   3 +-
 drivers/thermal/thermal_core.c| 216 +++
 drivers/thermal/thermal_helpers.c | 238 --
 3 files changed, 217 insertions(+), 240 deletions(-)
 delete mode 100644 drivers/thermal/thermal_helpers.c

diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 0c8b84a09b9aa..ed2fc83fe2128 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -4,8 +4,7 @@
 #
 
 obj-$(CONFIG_THERMAL)		+= thermal_sys.o
-thermal_sys-y			+= thermal_core.o thermal_sysfs.o \
-	thermal_helpers.o
+thermal_sys-y			+= thermal_core.o thermal_sysfs.o
 
 # interface to/from other layers providing sensors
 thermal_sys-$(CONFIG_THERMAL_HWMON)		+= thermal_hwmon.o
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index b71196eaf90e8..a9e927f7224e9 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -43,6 +43,222 @@ static bool power_off_triggered;
 
 static struct thermal_governor *def_governor;
 
+/*  Various helper functions */
+
+int get_tz_trend(struct thermal_zone_device *tz, int trip)
+{
+	enum thermal_trend trend;
+
+	if (tz->emul_temperature || !tz->ops->get_trend ||
+	tz->ops->get_trend(tz, trip, )) {
+		if (tz->temperature > tz->last_temperature)
+			trend = THERMAL_TREND_RAISING;
+		else if (tz->temperature < tz->last_temperature)
+			trend = THERMAL_TREND_DROPPING;
+		else
+			trend = THERMAL_TREND_STABLE;
+	}
+
+	return trend;
+}
+EXPORT_SYMBOL(get_tz_trend);
+
+struct thermal_instance *
+get_thermal_instance(struct thermal_zone_device *tz,
+		 struct thermal_cooling_device *cdev, int trip)
+{
+	struct thermal_instance *pos = NULL;
+	struct thermal_instance *target_instance = NULL;
+
+	mutex_lock(>lock);
+	mutex_lock(>lock);
+
+	list_for_each_entry(pos, >thermal_instances, tz_node) {
+		if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
+			target_instance = pos;
+			break;
+		}
+	}
+
+	mutex_unlock(>lock);
+	mutex_unlock(>lock);
+
+	return target_instance;
+}
+EXPORT_SYMBOL(get_thermal_instance);
+
+/**
+ * thermal_zone_get_temp() - returns the temperature of a thermal zone
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @temp: a valid pointer to where to store the resulting temperature.
+ *
+ * When a valid thermal zone reference is passed, it will fetch its
+ * temperature and fill @temp.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+int 

Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-01 Thread Zhang Rui
On Wed, 2020-07-01 at 09:35 +0200, Daniel Lezcano wrote:
> On 30/06/2020 17:09, Zhang Rui wrote:
> > Hi, Daniel,
> > 
> > seems that you forgot to cc linux-pm mailing list.
> > 
> > On Tue, 2020-06-30 at 17:16 +0530, Amit Kucheria wrote:
> > > On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
> > >  wrote:
> > > > 
> > > > The cdev, tz and governor list, as well as their respective
> > > > locks
> > > > are
> > > > statically defined in the thermal_core.c file.
> > > > 
> > > > In order to give a sane access to these list, like browsing all
> > > > the
> > > > thermal zones or all the cooling devices, let's define a set of
> > > > helpers where we pass a callback as a parameter to be called
> > > > for
> > > > each
> > > > thermal entity.
> > > > 
> > > > We keep the self-encapsulation and ensure the locks are
> > > > correctly
> > > > taken when looking at the list.
> > > > 
> > > > Signed-off-by: Daniel Lezcano 
> > > > ---
> > > >  drivers/thermal/thermal_core.c | 51
> > > > ++
> > > 
> > > Is the idea to not use thermal_helpers.c from now on? It fits
> > > perfectly with a patch I have to merge all its contents to
> > > thermal_core.c :-)
> > 
> > I agree these changes should be in thermal_helper.c
> 
> Oh, actually I remind put those functions in the thermal_core.c file
> because they need the locks which are statically defined in there.
> 
> If the functions are moved to thermal_helper.c that will imply to
> export
> the locks outside of the file, thus breaking the self-encapsulation.
> 
> Do you want to move them out?

Then no. I don't have any objection of removing thermal_helper.c, so
you can just leave these functions in thermal_core.c

thanks,
rui
> 
> 



Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-01 Thread Daniel Lezcano
On 30/06/2020 17:09, Zhang Rui wrote:
> Hi, Daniel,
> 
> seems that you forgot to cc linux-pm mailing list.
> 
> On Tue, 2020-06-30 at 17:16 +0530, Amit Kucheria wrote:
>> On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
>>  wrote:
>>>
>>> The cdev, tz and governor list, as well as their respective locks
>>> are
>>> statically defined in the thermal_core.c file.
>>>
>>> In order to give a sane access to these list, like browsing all the
>>> thermal zones or all the cooling devices, let's define a set of
>>> helpers where we pass a callback as a parameter to be called for
>>> each
>>> thermal entity.
>>>
>>> We keep the self-encapsulation and ensure the locks are correctly
>>> taken when looking at the list.
>>>
>>> Signed-off-by: Daniel Lezcano 
>>> ---
>>>  drivers/thermal/thermal_core.c | 51
>>> ++
>>
>> Is the idea to not use thermal_helpers.c from now on? It fits
>> perfectly with a patch I have to merge all its contents to
>> thermal_core.c :-)
> 
> I agree these changes should be in thermal_helper.c

Oh, actually I remind put those functions in the thermal_core.c file
because they need the locks which are statically defined in there.

If the functions are moved to thermal_helper.c that will imply to export
the locks outside of the file, thus breaking the self-encapsulation.

Do you want to move them out?


-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-07-01 Thread Daniel Lezcano
On 30/06/2020 20:46, Amit Kucheria wrote:
> On Tue, Jun 30, 2020 at 8:40 PM Zhang Rui  wrote:
>>
>> Hi, Daniel,
>>
>> seems that you forgot to cc linux-pm mailing list.
>>
>> On Tue, 2020-06-30 at 17:16 +0530, Amit Kucheria wrote:
>>> On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
>>>  wrote:

 The cdev, tz and governor list, as well as their respective locks
 are
 statically defined in the thermal_core.c file.

 In order to give a sane access to these list, like browsing all the
 thermal zones or all the cooling devices, let's define a set of
 helpers where we pass a callback as a parameter to be called for
 each
 thermal entity.

 We keep the self-encapsulation and ensure the locks are correctly
 taken when looking at the list.

 Signed-off-by: Daniel Lezcano 
 ---
  drivers/thermal/thermal_core.c | 51
 ++
>>>
>>> Is the idea to not use thermal_helpers.c from now on? It fits
>>> perfectly with a patch I have to merge all its contents to
>>> thermal_core.c :-)
>>
>> I agree these changes should be in thermal_helper.c
> 
> I was actually serious about killing thermal_helper.c :-)
> 
> What is the reason for those 5-6 functions to live outside
> thermal_core.c? Functions in thermal_helper.c are called by governors
> and drivers, just like the functions in thermal_core.c. I couldn't
> find a pattern.

I propose to move these functions in the thermal_helper.c for now as
requested by Rui. Then you can send a patch to merge thermal_helper.c to
thermal_core.c after and we can comment the move.



-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-06-30 Thread Amit Kucheria
On Tue, Jun 30, 2020 at 8:40 PM Zhang Rui  wrote:
>
> Hi, Daniel,
>
> seems that you forgot to cc linux-pm mailing list.
>
> On Tue, 2020-06-30 at 17:16 +0530, Amit Kucheria wrote:
> > On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
> >  wrote:
> > >
> > > The cdev, tz and governor list, as well as their respective locks
> > > are
> > > statically defined in the thermal_core.c file.
> > >
> > > In order to give a sane access to these list, like browsing all the
> > > thermal zones or all the cooling devices, let's define a set of
> > > helpers where we pass a callback as a parameter to be called for
> > > each
> > > thermal entity.
> > >
> > > We keep the self-encapsulation and ensure the locks are correctly
> > > taken when looking at the list.
> > >
> > > Signed-off-by: Daniel Lezcano 
> > > ---
> > >  drivers/thermal/thermal_core.c | 51
> > > ++
> >
> > Is the idea to not use thermal_helpers.c from now on? It fits
> > perfectly with a patch I have to merge all its contents to
> > thermal_core.c :-)
>
> I agree these changes should be in thermal_helper.c

I was actually serious about killing thermal_helper.c :-)

What is the reason for those 5-6 functions to live outside
thermal_core.c? Functions in thermal_helper.c are called by governors
and drivers, just like the functions in thermal_core.c. I couldn't
find a pattern.

Regards,
Amit


Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-06-30 Thread Zhang Rui
Hi, Daniel,

seems that you forgot to cc linux-pm mailing list.

On Tue, 2020-06-30 at 17:16 +0530, Amit Kucheria wrote:
> On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
>  wrote:
> > 
> > The cdev, tz and governor list, as well as their respective locks
> > are
> > statically defined in the thermal_core.c file.
> > 
> > In order to give a sane access to these list, like browsing all the
> > thermal zones or all the cooling devices, let's define a set of
> > helpers where we pass a callback as a parameter to be called for
> > each
> > thermal entity.
> > 
> > We keep the self-encapsulation and ensure the locks are correctly
> > taken when looking at the list.
> > 
> > Signed-off-by: Daniel Lezcano 
> > ---
> >  drivers/thermal/thermal_core.c | 51
> > ++
> 
> Is the idea to not use thermal_helpers.c from now on? It fits
> perfectly with a patch I have to merge all its contents to
> thermal_core.c :-)

I agree these changes should be in thermal_helper.c

thanks,
rui
> 
> 
> >  drivers/thermal/thermal_core.h |  9 ++
> >  2 files changed, 60 insertions(+)
> > 
> > diff --git a/drivers/thermal/thermal_core.c
> > b/drivers/thermal/thermal_core.c
> > index 2a3f83265d8b..e2f8d2550ecd 100644
> > --- a/drivers/thermal/thermal_core.c
> > +++ b/drivers/thermal/thermal_core.c
> > @@ -611,6 +611,57 @@ void
> > thermal_zone_device_rebind_exception(struct thermal_zone_device
> > *tz,
> > mutex_unlock(_list_lock);
> >  }
> > 
> > +int for_each_thermal_governor(int (*cb)(struct thermal_governor *,
> > void *),
> > + void *data)
> 
> 
> > +{
> > +   struct thermal_governor *gov;
> > +   int ret = 0;
> > +
> > +   mutex_lock(_governor_lock);
> > +   list_for_each_entry(gov, _governor_list,
> > governor_list) {
> > +   ret = cb(gov, data);
> > +   if (ret)
> > +   break;
> > +   }
> > +   mutex_unlock(_governor_lock);
> > +
> > +   return ret;
> > +}
> > +
> > +int for_each_thermal_cooling_device(int (*cb)(struct
> > thermal_cooling_device *,
> > + void *), void *data)
> > +{
> > +   struct thermal_cooling_device *cdev;
> > +   int ret = 0;
> > +
> > +   mutex_lock(_list_lock);
> > +   list_for_each_entry(cdev, _cdev_list, node) {
> > +   ret = cb(cdev, data);
> > +   if (ret)
> > +   break;
> > +   }
> > +   mutex_unlock(_list_lock);
> > +
> > +   return ret;
> > +}
> > +
> > +int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *,
> > void *),
> > + void *data)
> > +{
> > +   struct thermal_zone_device *tz;
> > +   int ret = 0;
> > +
> > +   mutex_lock(_list_lock);
> > +   list_for_each_entry(tz, _tz_list, node) {
> > +   ret = cb(tz, data);
> > +   if (ret)
> > +   break;
> > +   }
> > +   mutex_unlock(_list_lock);
> > +
> > +   return ret;
> > +}
> > +
> >  void thermal_zone_device_unbind_exception(struct
> > thermal_zone_device *tz,
> >   const char *cdev_type,
> > size_t size)
> >  {
> > diff --git a/drivers/thermal/thermal_core.h
> > b/drivers/thermal/thermal_core.h
> > index 4e271016b7a9..bb8f8aee79eb 100644
> > --- a/drivers/thermal/thermal_core.h
> > +++ b/drivers/thermal/thermal_core.h
> > @@ -41,6 +41,15 @@ extern struct thermal_governor
> > *__governor_thermal_table_end[];
> >  __governor < __governor_thermal_table_end; \
> >  __governor++)
> > 
> > +int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *,
> > void *),
> > + void *);
> > +
> > +int for_each_thermal_cooling_device(int (*cb)(struct
> > thermal_cooling_device *,
> > + void *), void *);
> > +
> > +int for_each_thermal_governor(int (*cb)(struct thermal_governor *,
> > void *),
> > + void *thermal_governor);
> > +
> >  struct thermal_attr {
> > struct device_attribute attr;
> > char name[THERMAL_NAME_LENGTH];
> > --
> > 2.17.1
> > 



Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-06-30 Thread Amit Kucheria
On Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano
 wrote:
>
> The cdev, tz and governor list, as well as their respective locks are
> statically defined in the thermal_core.c file.
>
> In order to give a sane access to these list, like browsing all the
> thermal zones or all the cooling devices, let's define a set of
> helpers where we pass a callback as a parameter to be called for each
> thermal entity.
>
> We keep the self-encapsulation and ensure the locks are correctly
> taken when looking at the list.
>
> Signed-off-by: Daniel Lezcano 
> ---
>  drivers/thermal/thermal_core.c | 51 ++

Is the idea to not use thermal_helpers.c from now on? It fits
perfectly with a patch I have to merge all its contents to
thermal_core.c :-)


>  drivers/thermal/thermal_core.h |  9 ++
>  2 files changed, 60 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 2a3f83265d8b..e2f8d2550ecd 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -611,6 +611,57 @@ void thermal_zone_device_rebind_exception(struct 
> thermal_zone_device *tz,
> mutex_unlock(_list_lock);
>  }
>
> +int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
> + void *data)


> +{
> +   struct thermal_governor *gov;
> +   int ret = 0;
> +
> +   mutex_lock(_governor_lock);
> +   list_for_each_entry(gov, _governor_list, governor_list) {
> +   ret = cb(gov, data);
> +   if (ret)
> +   break;
> +   }
> +   mutex_unlock(_governor_lock);
> +
> +   return ret;
> +}
> +
> +int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device 
> *,
> + void *), void *data)
> +{
> +   struct thermal_cooling_device *cdev;
> +   int ret = 0;
> +
> +   mutex_lock(_list_lock);
> +   list_for_each_entry(cdev, _cdev_list, node) {
> +   ret = cb(cdev, data);
> +   if (ret)
> +   break;
> +   }
> +   mutex_unlock(_list_lock);
> +
> +   return ret;
> +}
> +
> +int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
> + void *data)
> +{
> +   struct thermal_zone_device *tz;
> +   int ret = 0;
> +
> +   mutex_lock(_list_lock);
> +   list_for_each_entry(tz, _tz_list, node) {
> +   ret = cb(tz, data);
> +   if (ret)
> +   break;
> +   }
> +   mutex_unlock(_list_lock);
> +
> +   return ret;
> +}
> +
>  void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
>   const char *cdev_type, size_t size)
>  {
> diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
> index 4e271016b7a9..bb8f8aee79eb 100644
> --- a/drivers/thermal/thermal_core.h
> +++ b/drivers/thermal/thermal_core.h
> @@ -41,6 +41,15 @@ extern struct thermal_governor 
> *__governor_thermal_table_end[];
>  __governor < __governor_thermal_table_end; \
>  __governor++)
>
> +int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
> + void *);
> +
> +int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device 
> *,
> + void *), void *);
> +
> +int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
> + void *thermal_governor);
> +
>  struct thermal_attr {
> struct device_attribute attr;
> char name[THERMAL_NAME_LENGTH];
> --
> 2.17.1
>


[PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list

2020-06-25 Thread Daniel Lezcano
The cdev, tz and governor list, as well as their respective locks are
statically defined in the thermal_core.c file.

In order to give a sane access to these list, like browsing all the
thermal zones or all the cooling devices, let's define a set of
helpers where we pass a callback as a parameter to be called for each
thermal entity.

We keep the self-encapsulation and ensure the locks are correctly
taken when looking at the list.

Signed-off-by: Daniel Lezcano 
---
 drivers/thermal/thermal_core.c | 51 ++
 drivers/thermal/thermal_core.h |  9 ++
 2 files changed, 60 insertions(+)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 2a3f83265d8b..e2f8d2550ecd 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -611,6 +611,57 @@ void thermal_zone_device_rebind_exception(struct 
thermal_zone_device *tz,
mutex_unlock(_list_lock);
 }
 
+int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
+ void *data)
+{
+   struct thermal_governor *gov;
+   int ret = 0;
+
+   mutex_lock(_governor_lock);
+   list_for_each_entry(gov, _governor_list, governor_list) {
+   ret = cb(gov, data);
+   if (ret)
+   break;
+   }
+   mutex_unlock(_governor_lock);
+
+   return ret;
+}
+
+int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
+ void *), void *data)
+{
+   struct thermal_cooling_device *cdev;
+   int ret = 0;
+
+   mutex_lock(_list_lock);
+   list_for_each_entry(cdev, _cdev_list, node) {
+   ret = cb(cdev, data);
+   if (ret)
+   break;
+   }
+   mutex_unlock(_list_lock);
+
+   return ret;
+}
+
+int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
+ void *data)
+{
+   struct thermal_zone_device *tz;
+   int ret = 0;
+
+   mutex_lock(_list_lock);
+   list_for_each_entry(tz, _tz_list, node) {
+   ret = cb(tz, data);
+   if (ret)
+   break;
+   }
+   mutex_unlock(_list_lock);
+
+   return ret;
+}
+
 void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
  const char *cdev_type, size_t size)
 {
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 4e271016b7a9..bb8f8aee79eb 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -41,6 +41,15 @@ extern struct thermal_governor 
*__governor_thermal_table_end[];
 __governor < __governor_thermal_table_end; \
 __governor++)
 
+int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
+ void *);
+
+int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
+ void *), void *);
+
+int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
+ void *thermal_governor);
+
 struct thermal_attr {
struct device_attribute attr;
char name[THERMAL_NAME_LENGTH];
-- 
2.17.1