~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/lib/thermal/thermal.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: LGPL-2.1+
  2 // Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
  3 #include <stdio.h>
  4 #include <thermal.h>
  5 
  6 #include "thermal_nl.h"
  7 
  8 int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg)
  9 {
 10         int i, ret = 0;
 11 
 12         if (!cdev)
 13                 return 0;
 14 
 15         for (i = 0; cdev[i].id != -1; i++)
 16                 ret |= cb(&cdev[i], arg);
 17 
 18         return ret;
 19 }
 20 
 21 int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg)
 22 {
 23         int i, ret = 0;
 24 
 25         if (!tt)
 26                 return 0;
 27 
 28         for (i = 0; tt[i].id != -1; i++)
 29                 ret |= cb(&tt[i], arg);
 30 
 31         return ret;
 32 }
 33 
 34 int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg)
 35 {
 36         int i, ret = 0;
 37 
 38         if (!tz)
 39                 return 0;
 40 
 41         for (i = 0; tz[i].id != -1; i++)
 42                 ret |= cb(&tz[i], arg);
 43 
 44         return ret;
 45 }
 46 
 47 struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
 48                                                const char *name)
 49 {
 50         int i;
 51 
 52         if (!tz || !name)
 53                 return NULL;
 54 
 55         for (i = 0; tz[i].id != -1; i++) {
 56                 if (!strcmp(tz[i].name, name))
 57                         return &tz[i];
 58         }
 59 
 60         return NULL;
 61 }
 62 
 63 struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id)
 64 {
 65         int i;
 66 
 67         if (!tz || id < 0)
 68                 return NULL;
 69 
 70         for (i = 0; tz[i].id != -1; i++) {
 71                 if (tz[i].id == id)
 72                         return &tz[i];
 73         }
 74 
 75         return NULL;
 76 }
 77 
 78 static int __thermal_zone_discover(struct thermal_zone *tz, void *th)
 79 {
 80         if (thermal_cmd_get_trip(th, tz) < 0)
 81                 return -1;
 82 
 83         if (thermal_cmd_get_governor(th, tz))
 84                 return -1;
 85 
 86         return 0;
 87 }
 88 
 89 struct thermal_zone *thermal_zone_discover(struct thermal_handler *th)
 90 {
 91         struct thermal_zone *tz;
 92 
 93         if (thermal_cmd_get_tz(th, &tz) < 0)
 94                 return NULL;
 95 
 96         if (for_each_thermal_zone(tz, __thermal_zone_discover, th))
 97                 return NULL;
 98 
 99         return tz;
100 }
101 
102 void thermal_exit(struct thermal_handler *th)
103 {
104         thermal_cmd_exit(th);
105         thermal_events_exit(th);
106         thermal_sampling_exit(th);
107 
108         free(th);
109 }
110 
111 struct thermal_handler *thermal_init(struct thermal_ops *ops)
112 {
113         struct thermal_handler *th;
114 
115         th = malloc(sizeof(*th));
116         if (!th)
117                 return NULL;
118         th->ops = ops;
119 
120         if (thermal_events_init(th))
121                 goto out_free;
122 
123         if (thermal_sampling_init(th))
124                 goto out_free;
125 
126         if (thermal_cmd_init(th))
127                 goto out_free;
128 
129         return th;
130 
131 out_free:
132         free(th);
133 
134         return NULL;
135 }
136 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php