def get_secondary_bus(dmar_tbl, tmp_dev, tmp_fun): cmd = "lspci -xxx" secondary_bus_str = '' found_pci_bdf = False pci_bridge_header_type = False res = parser_lib.cmd_execute(cmd) while True: line = res.stdout.readline().decode("ascii") if not line: break if ':' not in line or len(line.strip().split(":")) < 1: continue if not found_pci_bdf: if '.' not in line.strip(): continue bus = int(line.strip().split(":")[0], 16) dev = int(line.strip().split()[0].split(":")[1].split(".")[0], 16) fun = int( line.strip().split()[0].split(":")[1].split(".")[1].strip(), 16) if bus == dmar_tbl.dmar_dev_scope.bus and dev == tmp_dev and fun == tmp_fun: found_pci_bdf = True continue else: if "00:" == line.strip().split()[0]: # PCI Header type stores in 0xE if len(line.split()) >= 16 and int( line.strip().split()[15], 16) & 0x7 == PCI_BRIDGE_HEADER: pci_bridge_header_type = True continue if not pci_bridge_header_type: continue # found the pci device, parse the secondary bus if "10:" == line.strip().split()[0]: # Secondary PCI BUS number stores in 0x18 secondary_bus_str = line.split()[9] found_pci_bdf = False pci_bridge_header_type = False break # the pci device has secondary bus if secondary_bus_str: dmar_tbl.dmar_dev_scope.bus = int(secondary_bus_str, 16)
def native_check(): """Check if this is natvie os""" cmd = "cpuid -r -l 0x01" res = parser_lib.cmd_execute(cmd) while True: line = parser_lib.decode_stdout(res) if line: if len(line.split()) <= 2: continue reg_value = line.split()[4].split('=')[1] break return int(reg_value, 16) & 0x80000000 == 0
def detected_ttys(): ttys_cnt = 8 tty_used_list = [] for s_inc in range(ttys_cnt): cmd = 'stty -F /dev/ttyS{}'.format(s_inc) res = parser_lib.cmd_execute('{}'.format(cmd)) while True: line = res.stdout.readline().decode('ascii') line_len = len(line.split()) if not line_len or line.split()[-1] == 'error': break ttys_n = "/dev/ttyS{}".format(s_inc) tty_used_list.append(ttys_n) break return tty_used_list
def dump_cpuid_reg(cmd, reg): """execute the cmd of cpuid, and return the register value by reg :param cmd: command what can be executed in shell :param reg: register name """ res = parser_lib.cmd_execute(cmd) if reg == "eax": idx = 2 if reg == "ebx": idx = 3 if reg == "edx": idx = 5 while True: line = parser_lib.decode_stdout(res) if not line: break if len(line.split()) <= 2: continue reg_value = line.split()[idx].split('=')[1] if reg == "eax": res_info = int(reg_value, 16) + 1 break elif reg == "ebx": res_info = [] if int(reg_value, 16) & RDT_TYPE['L2'] != 0: res_info.append("L2") if int(reg_value, 16) & RDT_TYPE['L3'] != 0: res_info.append("L3") if int(reg_value, 16) & RDT_TYPE['MBA'] != 0: res_info.append("MBA") break elif reg == "edx": res_info = int(reg_value, 16) + 1 break return res_info
def dump_cpuid_reg(cmd, reg): """execute the cmd of cpuid, and return the register value by reg :param cmd: command what can be executed in shell :param reg: register name """ cache_t = '' res = parser_lib.cmd_execute(cmd) if reg == "ebx": idx = 3 if reg == "edx": idx = 5 while True: line = parser_lib.decode_stdout(res) if not line: break if len(line.split()) <= 2: continue reg_value = line.split()[idx].split('=')[1] if reg == "ebx": if int(reg_value, 16) & CACHE_TYPE['L2'] != 0: cache_t = "L2" break elif int(reg_value, 16) & CACHE_TYPE['L3'] != 0: cache_t = "L3" break else: cache_t = False break elif reg == "edx": cache_t = int(reg_value, 16) + 1 break return cache_t
def irq2bdf(irq_n): cmd = 'lspci -vv' res = parser_lib.cmd_execute(cmd) bdf = '' irq = 0 while True: line = res.stdout.readline().decode('ascii') if not line: break if ':' not in line: continue if '.' in line.split()[0]: bdf = line.split()[0] if "Interrupt:" in line.strip(): irq = line.split()[-1] if irq == irq_n and bdf: break return bdf