clk.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Copyright (c) NXP 2019
  4. import gdb
  5. import sys
  6. from linux import utils, lists, constants
  7. clk_core_type = utils.CachedType("struct clk_core")
  8. def clk_core_for_each_child(hlist_head):
  9. return lists.hlist_for_each_entry(hlist_head,
  10. clk_core_type.get_type().pointer(), "child_node")
  11. class LxClkSummary(gdb.Command):
  12. """Print clk tree summary
  13. Output is a subset of /sys/kernel/debug/clk/clk_summary
  14. No calls are made during printing, instead a (c) if printed after values which
  15. are cached and potentially out of date"""
  16. def __init__(self):
  17. super(LxClkSummary, self).__init__("lx-clk-summary", gdb.COMMAND_DATA)
  18. def show_subtree(self, clk, level):
  19. gdb.write("%*s%-*s %7d %8d %8d %11lu%s\n" % (
  20. level * 3 + 1, "",
  21. 30 - level * 3,
  22. clk['name'].string(),
  23. clk['enable_count'],
  24. clk['prepare_count'],
  25. clk['protect_count'],
  26. clk['rate'],
  27. '(c)' if clk['flags'] & constants.LX_CLK_GET_RATE_NOCACHE else ' '))
  28. for child in clk_core_for_each_child(clk['children']):
  29. self.show_subtree(child, level + 1)
  30. def invoke(self, arg, from_tty):
  31. if utils.gdb_eval_or_none("clk_root_list") is None:
  32. raise gdb.GdbError("No clocks registered")
  33. gdb.write(" enable prepare protect \n")
  34. gdb.write(" clock count count count rate \n")
  35. gdb.write("------------------------------------------------------------------------\n")
  36. for clk in clk_core_for_each_child(gdb.parse_and_eval("clk_root_list")):
  37. self.show_subtree(clk, 0)
  38. for clk in clk_core_for_each_child(gdb.parse_and_eval("clk_orphan_list")):
  39. self.show_subtree(clk, 0)
  40. LxClkSummary()
  41. class LxClkCoreLookup(gdb.Function):
  42. """Find struct clk_core by name"""
  43. def __init__(self):
  44. super(LxClkCoreLookup, self).__init__("lx_clk_core_lookup")
  45. def lookup_hlist(self, hlist_head, name):
  46. for child in clk_core_for_each_child(hlist_head):
  47. if child['name'].string() == name:
  48. return child
  49. result = self.lookup_hlist(child['children'], name)
  50. if result:
  51. return result
  52. def invoke(self, name):
  53. name = name.string()
  54. return (self.lookup_hlist(gdb.parse_and_eval("clk_root_list"), name) or
  55. self.lookup_hlist(gdb.parse_and_eval("clk_orphan_list"), name))
  56. LxClkCoreLookup()