Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) # Copyright (c) NXP 2019
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) import gdb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) from linux.utils import CachedType
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) from linux.utils import container_of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) from linux.lists import list_for_each_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) device_private_type = CachedType('struct device_private')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) device_type = CachedType('struct device')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) subsys_private_type = CachedType('struct subsys_private')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) kobject_type = CachedType('struct kobject')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) kset_type = CachedType('struct kset')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) bus_type = CachedType('struct bus_type')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) class_type = CachedType('struct class')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) def dev_name(dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)     dev_init_name = dev['init_name']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)     if dev_init_name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)         return dev_init_name.string()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)     return dev['kobj']['name'].string()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) def kset_for_each_object(kset):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)     return list_for_each_entry(kset['list'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)             kobject_type.get_type().pointer(), "entry")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) def for_each_bus():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)     for kobj in kset_for_each_object(gdb.parse_and_eval('bus_kset')):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)         subsys = container_of(kobj, kset_type.get_type().pointer(), 'kobj')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)         subsys_priv = container_of(subsys, subsys_private_type.get_type().pointer(), 'subsys')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)         yield subsys_priv['bus']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) def for_each_class():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)     for kobj in kset_for_each_object(gdb.parse_and_eval('class_kset')):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)         subsys = container_of(kobj, kset_type.get_type().pointer(), 'kobj')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)         subsys_priv = container_of(subsys, subsys_private_type.get_type().pointer(), 'subsys')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)         yield subsys_priv['class']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) def get_bus_by_name(name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)     for item in for_each_bus():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)         if item['name'].string() == name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)             return item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)     raise gdb.GdbError("Can't find bus type {!r}".format(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) def get_class_by_name(name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)     for item in for_each_class():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)         if item['name'].string() == name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)             return item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)     raise gdb.GdbError("Can't find device class {!r}".format(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) klist_type = CachedType('struct klist')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) klist_node_type = CachedType('struct klist_node')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) def klist_for_each(klist):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)     return list_for_each_entry(klist['k_list'],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)                 klist_node_type.get_type().pointer(), 'n_node')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) def bus_for_each_device(bus):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)     for kn in klist_for_each(bus['p']['klist_devices']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)         dp = container_of(kn, device_private_type.get_type().pointer(), 'knode_bus')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)         yield dp['device']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) def class_for_each_device(cls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)     for kn in klist_for_each(cls['p']['klist_devices']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)         dp = container_of(kn, device_private_type.get_type().pointer(), 'knode_class')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)         yield dp['device']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) def device_for_each_child(dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)     for kn in klist_for_each(dev['p']['klist_children']):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)         dp = container_of(kn, device_private_type.get_type().pointer(), 'knode_parent')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)         yield dp['device']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) def _show_device(dev, level=0, recursive=False):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)     gdb.write('{}dev {}:\t{}\n'.format('\t' * level, dev_name(dev), dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)     if recursive:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)         for child in device_for_each_child(dev):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)             _show_device(child, level + 1, recursive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) class LxDeviceListBus(gdb.Command):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)     '''Print devices on a bus (or all buses if not specified)'''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)     def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)         super(LxDeviceListBus, self).__init__('lx-device-list-bus', gdb.COMMAND_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)     def invoke(self, arg, from_tty):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)         if not arg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)             for bus in for_each_bus():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)                 gdb.write('bus {}:\t{}\n'.format(bus['name'].string(), bus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)                 for dev in bus_for_each_device(bus):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)                     _show_device(dev, level=1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)         else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)             bus = get_bus_by_name(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)             if not bus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)                 raise gdb.GdbError("Can't find bus {!r}".format(arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)             for dev in bus_for_each_device(bus):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)                 _show_device(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) class LxDeviceListClass(gdb.Command):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)     '''Print devices in a class (or all classes if not specified)'''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)     def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)         super(LxDeviceListClass, self).__init__('lx-device-list-class', gdb.COMMAND_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)     def invoke(self, arg, from_tty):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)         if not arg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)             for cls in for_each_class():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)                 gdb.write("class {}:\t{}\n".format(cls['name'].string(), cls))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)                 for dev in class_for_each_device(cls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)                     _show_device(dev, level=1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)         else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)             cls = get_class_by_name(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)             for dev in class_for_each_device(cls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)                 _show_device(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) class LxDeviceListTree(gdb.Command):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)     '''Print a device and its children recursively'''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)     def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)         super(LxDeviceListTree, self).__init__('lx-device-list-tree', gdb.COMMAND_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)     def invoke(self, arg, from_tty):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)         if not arg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)             raise gdb.GdbError('Please provide pointer to struct device')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)         dev = gdb.parse_and_eval(arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)         if dev.type != device_type.get_type().pointer():
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)             raise gdb.GdbError('Please provide pointer to struct device')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)         _show_device(dev, level=0, recursive=True)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) class LxDeviceFindByBusName(gdb.Function):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)     '''Find struct device by bus and name (both strings)'''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)     def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)         super(LxDeviceFindByBusName, self).__init__('lx_device_find_by_bus_name')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)     def invoke(self, bus, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)         name = name.string()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)         bus = get_bus_by_name(bus.string())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)         for dev in bus_for_each_device(bus):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)             if dev_name(dev) == name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)                 return dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) class LxDeviceFindByClassName(gdb.Function):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)     '''Find struct device by class and name (both strings)'''
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)     def __init__(self):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)         super(LxDeviceFindByClassName, self).__init__('lx_device_find_by_class_name')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)     def invoke(self, cls, name):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)         name = name.string()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)         cls = get_class_by_name(cls.string())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)         for dev in class_for_each_device(cls):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)             if dev_name(dev) == name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)                 return dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) LxDeviceListBus()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) LxDeviceListClass()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) LxDeviceListTree()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) LxDeviceFindByBusName()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) LxDeviceFindByClassName()