blob: d89ce07089a5177a463c18b416e571772b2c9348 [file] [log] [blame]
Sergei Trofimov4e6afe92015-10-09 09:30:04 +01001from devlib.module import Module
2
3
4class HotplugModule(Module):
5
6 name = 'hotplug'
7 base_path = '/sys/devices/system/cpu'
8
9 @classmethod
10 def probe(cls, target): # pylint: disable=arguments-differ
11 path = cls._cpu_path(target, 0)
12 return target.file_exists(path) and target.is_rooted
13
14 @classmethod
15 def _cpu_path(cls, target, cpu):
16 if isinstance(cpu, int):
17 cpu = 'cpu{}'.format(cpu)
18 return target.path.join(cls.base_path, cpu, 'online')
19
20 def online_all(self):
21 self.online(*range(self.target.number_of_cpus))
22
23 def online(self, *args):
24 for cpu in args:
25 self.hotplug(cpu, online=True)
26
27 def offline(self, *args):
28 for cpu in args:
29 self.hotplug(cpu, online=False)
30
31 def hotplug(self, cpu, online):
32 path = self._cpu_path(self.target, cpu)
33 value = 1 if online else 0
34 self.target.write_value(path, value)
35