1*c6e2b45aSAnthony Nandaa#!/usr/bin/env python3 2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 3502d84bdSDexuan Cui 4502d84bdSDexuan Cuiimport os 5502d84bdSDexuan Cuifrom optparse import OptionParser 6502d84bdSDexuan Cui 75912e791SAdrian Vladuhelp_msg = "print verbose messages. Try -vv, -vvv for more verbose messages" 8502d84bdSDexuan Cuiparser = OptionParser() 95912e791SAdrian Vladuparser.add_option( 105912e791SAdrian Vladu "-v", "--verbose", dest="verbose", help=help_msg, action="count") 11502d84bdSDexuan Cui 12502d84bdSDexuan Cui(options, args) = parser.parse_args() 13502d84bdSDexuan Cui 14502d84bdSDexuan Cuiverbose = 0 15502d84bdSDexuan Cuiif options.verbose is not None: 16502d84bdSDexuan Cui verbose = options.verbose 17502d84bdSDexuan Cui 18502d84bdSDexuan Cuivmbus_sys_path = '/sys/bus/vmbus/devices' 19502d84bdSDexuan Cuiif not os.path.isdir(vmbus_sys_path): 208a99c920SOlaf Hering print("%s doesn't exist: exiting..." % vmbus_sys_path) 21502d84bdSDexuan Cui exit(-1) 22502d84bdSDexuan Cui 23502d84bdSDexuan Cuivmbus_dev_dict = { 24502d84bdSDexuan Cui '{0e0b6031-5213-4934-818b-38d90ced39db}': '[Operating system shutdown]', 25502d84bdSDexuan Cui '{9527e630-d0ae-497b-adce-e80ab0175caf}': '[Time Synchronization]', 26502d84bdSDexuan Cui '{57164f39-9115-4e78-ab55-382f3bd5422d}': '[Heartbeat]', 27502d84bdSDexuan Cui '{a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}': '[Data Exchange]', 28502d84bdSDexuan Cui '{35fa2e29-ea23-4236-96ae-3a6ebacba440}': '[Backup (volume checkpoint)]', 29502d84bdSDexuan Cui '{34d14be3-dee4-41c8-9ae7-6b174977c192}': '[Guest services]', 30502d84bdSDexuan Cui '{525074dc-8985-46e2-8057-a307dc18a502}': '[Dynamic Memory]', 31502d84bdSDexuan Cui '{cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}': 'Synthetic mouse', 32502d84bdSDexuan Cui '{f912ad6d-2b17-48ea-bd65-f927a61c7684}': 'Synthetic keyboard', 33502d84bdSDexuan Cui '{da0a7802-e377-4aac-8e77-0558eb1073f8}': 'Synthetic framebuffer adapter', 34502d84bdSDexuan Cui '{f8615163-df3e-46c5-913f-f2d2f965ed0e}': 'Synthetic network adapter', 35502d84bdSDexuan Cui '{32412632-86cb-44a2-9b5c-50d1417354f5}': 'Synthetic IDE Controller', 36502d84bdSDexuan Cui '{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}': 'Synthetic SCSI Controller', 37502d84bdSDexuan Cui '{2f9bcc4a-0069-4af3-b76b-6fd0be528cda}': 'Synthetic fiber channel adapter', 38502d84bdSDexuan Cui '{8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}': 'Synthetic RDMA adapter', 39552beb49SVitaly Kuznetsov '{44c4f61d-4444-4400-9d52-802e27ede19f}': 'PCI Express pass-through', 40502d84bdSDexuan Cui '{276aacf4-ac15-426c-98dd-7521ad3f01fe}': '[Reserved system device]', 41502d84bdSDexuan Cui '{f8e65716-3cb3-4a06-9a60-1889c5cccab5}': '[Reserved system device]', 42502d84bdSDexuan Cui '{3375baf4-9e15-4b30-b765-67acb10d607b}': '[Reserved system device]', 43502d84bdSDexuan Cui} 44502d84bdSDexuan Cui 455912e791SAdrian Vladu 46502d84bdSDexuan Cuidef get_vmbus_dev_attr(dev_name, attr): 47502d84bdSDexuan Cui try: 48502d84bdSDexuan Cui f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r') 49502d84bdSDexuan Cui lines = f.readlines() 50502d84bdSDexuan Cui f.close() 51502d84bdSDexuan Cui except IOError: 52502d84bdSDexuan Cui lines = [] 53502d84bdSDexuan Cui 54502d84bdSDexuan Cui return lines 55502d84bdSDexuan Cui 565912e791SAdrian Vladu 57502d84bdSDexuan Cuiclass VMBus_Dev: 58502d84bdSDexuan Cui pass 59502d84bdSDexuan Cui 60502d84bdSDexuan Cui 61502d84bdSDexuan Cuivmbus_dev_list = [] 62502d84bdSDexuan Cui 63502d84bdSDexuan Cuifor f in os.listdir(vmbus_sys_path): 64502d84bdSDexuan Cui vmbus_id = get_vmbus_dev_attr(f, 'id')[0].strip() 65502d84bdSDexuan Cui class_id = get_vmbus_dev_attr(f, 'class_id')[0].strip() 66502d84bdSDexuan Cui device_id = get_vmbus_dev_attr(f, 'device_id')[0].strip() 67502d84bdSDexuan Cui dev_desc = vmbus_dev_dict.get(class_id, 'Unknown') 68502d84bdSDexuan Cui 69502d84bdSDexuan Cui chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping') 70502d84bdSDexuan Cui chn_vp_mapping = [c.strip() for c in chn_vp_mapping] 715912e791SAdrian Vladu chn_vp_mapping = sorted( 725912e791SAdrian Vladu chn_vp_mapping, key=lambda c: int(c.split(':')[0])) 73502d84bdSDexuan Cui 745912e791SAdrian Vladu chn_vp_mapping = [ 755912e791SAdrian Vladu '\tRel_ID=%s, target_cpu=%s' % 765912e791SAdrian Vladu (c.split(':')[0], c.split(':')[1]) for c in chn_vp_mapping 775912e791SAdrian Vladu ] 78502d84bdSDexuan Cui d = VMBus_Dev() 79502d84bdSDexuan Cui d.sysfs_path = '%s/%s' % (vmbus_sys_path, f) 80502d84bdSDexuan Cui d.vmbus_id = vmbus_id 81502d84bdSDexuan Cui d.class_id = class_id 82502d84bdSDexuan Cui d.device_id = device_id 83502d84bdSDexuan Cui d.dev_desc = dev_desc 84502d84bdSDexuan Cui d.chn_vp_mapping = '\n'.join(chn_vp_mapping) 85502d84bdSDexuan Cui if d.chn_vp_mapping: 86502d84bdSDexuan Cui d.chn_vp_mapping += '\n' 87502d84bdSDexuan Cui 88502d84bdSDexuan Cui vmbus_dev_list.append(d) 89502d84bdSDexuan Cui 90502d84bdSDexuan Cui 91502d84bdSDexuan Cuivmbus_dev_list = sorted(vmbus_dev_list, key=lambda d: int(d.vmbus_id)) 92502d84bdSDexuan Cui 93502d84bdSDexuan Cuiformat0 = '%2s: %s' 94502d84bdSDexuan Cuiformat1 = '%2s: Class_ID = %s - %s\n%s' 95502d84bdSDexuan Cuiformat2 = '%2s: Class_ID = %s - %s\n\tDevice_ID = %s\n\tSysfs path: %s\n%s' 96502d84bdSDexuan Cui 97502d84bdSDexuan Cuifor d in vmbus_dev_list: 98502d84bdSDexuan Cui if verbose == 0: 998a99c920SOlaf Hering print(('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc)) 100502d84bdSDexuan Cui elif verbose == 1: 1015912e791SAdrian Vladu print( 1025912e791SAdrian Vladu ('VMBUS ID ' + format1) % 1035912e791SAdrian Vladu (d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping) 1045912e791SAdrian Vladu ) 105502d84bdSDexuan Cui else: 1065912e791SAdrian Vladu print( 1075912e791SAdrian Vladu ('VMBUS ID ' + format2) % 1085912e791SAdrian Vladu ( 1095912e791SAdrian Vladu d.vmbus_id, d.class_id, d.dev_desc, 1105912e791SAdrian Vladu d.device_id, d.sysfs_path, d.chn_vp_mapping 1115912e791SAdrian Vladu ) 1125912e791SAdrian Vladu ) 113