Merge tag 'for-linus-5.3a-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / scripts / gdb / linux / clk.py
CommitLineData
d1e9710b
LC
1# SPDX-License-Identifier: GPL-2.0
2#
3# Copyright (c) NXP 2019
4
5import gdb
6import sys
7
e7e6f462 8from linux import utils, lists, constants
d1e9710b
LC
9
10clk_core_type = utils.CachedType("struct clk_core")
11
12
13def clk_core_for_each_child(hlist_head):
14 return lists.hlist_for_each_entry(hlist_head,
15 clk_core_type.get_type().pointer(), "child_node")
16
17
18class LxClkSummary(gdb.Command):
e7e6f462
LC
19 """Print clk tree summary
20
21Output is a subset of /sys/kernel/debug/clk/clk_summary
22
23No calls are made during printing, instead a (c) if printed after values which
24are cached and potentially out of date"""
d1e9710b
LC
25
26 def __init__(self):
27 super(LxClkSummary, self).__init__("lx-clk-summary", gdb.COMMAND_DATA)
28
29 def show_subtree(self, clk, level):
e7e6f462 30 gdb.write("%*s%-*s %7d %8d %8d %11lu%s\n" % (
d1e9710b
LC
31 level * 3 + 1, "",
32 30 - level * 3,
33 clk['name'].string(),
34 clk['enable_count'],
35 clk['prepare_count'],
e7e6f462
LC
36 clk['protect_count'],
37 clk['rate'],
38 '(c)' if clk['flags'] & constants.LX_CLK_GET_RATE_NOCACHE else ' '))
d1e9710b
LC
39
40 for child in clk_core_for_each_child(clk['children']):
41 self.show_subtree(child, level + 1)
42
43 def invoke(self, arg, from_tty):
e7e6f462
LC
44 gdb.write(" enable prepare protect \n")
45 gdb.write(" clock count count count rate \n")
46 gdb.write("------------------------------------------------------------------------\n")
d1e9710b
LC
47 for clk in clk_core_for_each_child(gdb.parse_and_eval("clk_root_list")):
48 self.show_subtree(clk, 0)
49 for clk in clk_core_for_each_child(gdb.parse_and_eval("clk_orphan_list")):
50 self.show_subtree(clk, 0)
51
52
53LxClkSummary()
988b2686
LC
54
55
56class LxClkCoreLookup(gdb.Function):
57 """Find struct clk_core by name"""
58
59 def __init__(self):
60 super(LxClkCoreLookup, self).__init__("lx_clk_core_lookup")
61
62 def lookup_hlist(self, hlist_head, name):
63 for child in clk_core_for_each_child(hlist_head):
64 if child['name'].string() == name:
65 return child
66 result = self.lookup_hlist(child['children'], name)
67 if result:
68 return result
69
70 def invoke(self, name):
71 name = name.string()
72 return (self.lookup_hlist(gdb.parse_and_eval("clk_root_list"), name) or
73 self.lookup_hlist(gdb.parse_and_eval("clk_orphan_list"), name))
74
75
76LxClkCoreLookup()