diff --git a/misc/acrn-config/board_config/acpi_platform_h.py b/misc/acrn-config/board_config/acpi_platform_h.py index c5dbf16c9..351b22c06 100644 --- a/misc/acrn-config/board_config/acpi_platform_h.py +++ b/misc/acrn-config/board_config/acpi_platform_h.py @@ -31,7 +31,12 @@ class OverridAccessSize(): def multi_parser(line, s_line, pm_ac_sz, config): - """Multi parser the line""" + """Multi parser the line + :param line: it is a line read from default_acpi_info.h + :param s_line: it is a line read from board information file + :param pm_ac_sz: it is a class for access size which would be override + :param config: it is a file pointer to write acpi information + """ addr = ['PM1A_EVT_ADDRESS', 'PM1B_EVT_ADDRESS', 'PM1A_CNT_ADDRESS', 'PM1B_CNT_ADDRESS'] space_id = ['PM1A_EVT_SPACE_ID', 'PM1B_EVT_SPACE_ID', 'PM1A_CNT_SPACE_ID', 'PM1B_CNT_SPACE_ID'] @@ -71,7 +76,12 @@ def multi_parser(line, s_line, pm_ac_sz, config): def multi_info_parser(config, default_platform, msg_s, msg_e): - """Parser multi information""" + """Parser multi information + :param config: it is a file pointer to write acpi information + :param default_platform: it is the default_acpi_info.h in acrn-hypervisor + :param msg_s: it is a pattern of key stings what start to match from board information + :param msg_e: it is a pattern of key stings what end to match from board information + """ write_direct = ['PM1A_EVT_ACCESS_SIZE', 'PM1A_EVT_ADDRESS', 'PM1A_CNT_ADDRESS'] pm_ac_sz = OverridAccessSize() @@ -99,7 +109,11 @@ def multi_info_parser(config, default_platform, msg_s, msg_e): def write_direct_info_parser(config, msg_s, msg_e): - """Direct to write""" + """Direct to write + :param config: it is a file pointer to write acpi information + :param msg_s: it is a pattern of key stings what start to match from board information + :param msg_e: it is a pattern of key stings what end to match from board information + """ vector_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, msg_s, msg_e) for vector in vector_lines: @@ -109,7 +123,9 @@ def write_direct_info_parser(config, msg_s, msg_e): def drhd_info_parser(config): - """Parser DRHD information""" + """Parser DRHD information + :param config: it is a file pointer to write acpi information + """ prev_num = 0 drhd_lines = board_cfg_lib.get_info( @@ -133,7 +149,10 @@ def drhd_info_parser(config): def platform_info_parser(config, default_platform): - """Parser ACPI information""" + """Parser ACPI information + :param config: it is a file pointer to write acpi information + :param default_platform: it is the default_acpi_info.h in acrn-hypervisor + """ print("\n/* pm sstate data */", file=config) multi_info_parser(config, default_platform, "", "") multi_info_parser(config, default_platform, "", "") @@ -146,7 +165,10 @@ def platform_info_parser(config, default_platform): def generate_file(config, default_platform): - """write board_name_acpi_info.h""" + """write board_name_acpi_info.h + :param config: it is a file pointer to write acpi information + :param default_platform: it is the default_acpi_info.h in acrn-hypervisor + """ print("{}".format(board_cfg_lib.HEADER_LICENSE), file=config) print("{}".format(PLATFORM_HEADER), file=config) diff --git a/misc/acrn-config/board_config/board_c.py b/misc/acrn-config/board_config/board_c.py index f55ace01e..07c66a55c 100644 --- a/misc/acrn-config/board_config/board_c.py +++ b/misc/acrn-config/board_config/board_c.py @@ -26,7 +26,9 @@ def clos_info_parser(): def gen_cat(config): - """Get CAT information""" + """Get CAT information + :param config: it is a file pointer of board information for writing to + """ (cache_support, clos_max) = clos_info_parser() print("\n#include ", file=config) @@ -48,7 +50,8 @@ def gen_cat(config): elif cache_support == "L3": print("\t\t.msr_index = {0}U,".format(hex(0x00000C90+i_cnt)), file=config) else: - board_cfg_lib.print_red("The input of board_info.txt was corrupted!") + board_cfg_lib.print_red("The input of {} was corrupted!".format( + board_cfg_lib.BOARD_INFO_FILE)) sys.exit(1) print("\t},", file=config) @@ -61,7 +64,9 @@ def gen_cat(config): def gen_px_cx(config): - """Get Px/Cx and store them to board.c""" + """Get Px/Cx and store them to board.c + :param config: it is a file pointer of board information for writing to + """ cpu_brand_lines = board_cfg_lib.get_info( board_cfg_lib.BOARD_INFO_FILE, "", "") cx_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "", "") @@ -92,7 +97,9 @@ def gen_px_cx(config): def generate_file(config): - """Start to generate board.c""" + """Start to generate board.c + :param config: it is a file pointer of board information for writing to + """ print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config) # insert bios info into board.c diff --git a/misc/acrn-config/board_config/board_cfg_gen.py b/misc/acrn-config/board_config/board_cfg_gen.py index f18f5f52c..0eeb70091 100755 --- a/misc/acrn-config/board_config/board_cfg_gen.py +++ b/misc/acrn-config/board_config/board_cfg_gen.py @@ -54,7 +54,10 @@ def prepare(): def gen_patch(srcs_list, board_name): - """Generate patch and apply to local source code""" + """Generate patch and apply to local source code + :param srcs_list: it is a list what contains source files + :param board_name: board name + """ changes = ' '.join(srcs_list) git_add = "git add {}".format(changes) subprocess.call(git_add, shell=True, stdout=subprocess.PIPE, @@ -67,7 +70,9 @@ def gen_patch(srcs_list, board_name): def main(board_info_file): - """This is main function to start generate source code related with board""" + """This is main function to start generate source code related with board + :param board_info_file: it is a file what contains board information for script to read from + """ board = '' config_srcs = [] config_dirs = [] @@ -101,7 +106,7 @@ def main(board_info_file): with open(config_platform, 'w+') as config: acpi_platform_h.generate_file(config, ACRN_DEFAULT_PLATFORM) - # move changes to patch, and applay to the source code + # move changes to patch, and apply to the source code gen_patch(config_srcs, board) if board not in BOARD_NAMES: @@ -131,7 +136,6 @@ if __name__ == '__main__': board_cfg_lib.print_red("{} is not exist!".format(BOARD_INFO_FILE)) sys.exit(1) - # board_info.txt will be override board_cfg_lib.BOARD_INFO_FILE = BOARD_INFO_FILE main(BOARD_INFO_FILE) diff --git a/misc/acrn-config/board_config/board_cfg_lib.py b/misc/acrn-config/board_config/board_cfg_lib.py index 0a3a76133..9c884ae13 100644 --- a/misc/acrn-config/board_config/board_cfg_lib.py +++ b/misc/acrn-config/board_config/board_cfg_lib.py @@ -28,7 +28,10 @@ HEADER_LICENSE = open_license() + "\n" def print_yel(msg, warn=False): - """Print the message with color of yellow""" + """Print the message with color of yellow + :param msg: the stings which will be output to STDOUT + :param warn: the condition if needs to be output the color of yellow with 'Warning' + """ if warn: print("\033[1;33mWarning\033[0m:"+msg) else: @@ -36,7 +39,10 @@ def print_yel(msg, warn=False): def print_red(msg, err=False): - """Print the message with color of red""" + """Print the message with color of red + :param msg: the stings which will be output to STDOUT + :param err: the condition if needs to be output the color of red with 'Error' + """ if err: print("\033[1;31mError\033[0m:"+msg) else: @@ -44,7 +50,9 @@ def print_red(msg, err=False): def get_board_name(board_info): - """Get board name""" + """Get board name from board.xml at fist line + :param board_info: it is a file what contains board information for script to read from + """ with open(board_info, 'rt') as f_board: line = f_board.readline() if not "board=" in line: @@ -56,7 +64,11 @@ def get_board_name(board_info): def get_info(board_info, msg_s, msg_e): - """Get information which specify by argument""" + """Get information which specify by argument + :param board_info: it is a file what contains board information for script to read from + :param msg_s: it is a pattern of key stings what start to match from board information + :param msg_e: it is a pattern of key stings what end to match from board information + """ info_start = False info_end = False info_lines = [] @@ -93,7 +105,9 @@ def get_info(board_info, msg_s, msg_e): def handle_bios_info(config): - """Handle bios information""" + """Handle bios information + :param config: it is a file pointer of bios information for writing to + """ bios_lines = get_info(BOARD_INFO_FILE, "", "") board_lines = get_info(BOARD_INFO_FILE, "", "") print("/*", file=config) @@ -116,9 +130,9 @@ def handle_bios_info(config): i_cnt += 1 - for mics_info in bios_board_info: - if mics_info == " ".join(line.split()[0:1]) or mics_info == \ - " ".join(line.split()[0:2]) or mics_info == " ".join(line.split()[0:3]): + for misc_info in bios_board_info: + if misc_info == " ".join(line.split()[0:1]) or misc_info == \ + " ".join(line.split()[0:2]) or misc_info == " ".join(line.split()[0:3]): print(" * {0}".format(line.strip()), file=config) print(" */", file=config) diff --git a/misc/acrn-config/board_config/pci_devices_h.py b/misc/acrn-config/board_config/pci_devices_h.py index 0ebedaf5b..4bd0999e2 100644 --- a/misc/acrn-config/board_config/pci_devices_h.py +++ b/misc/acrn-config/board_config/pci_devices_h.py @@ -68,7 +68,12 @@ def parser_pci(): def write_pbdf(i_cnt, bdf, subname, config): - """Parser and generate pbdf""" + """Parser and generate pbdf + :param i_cnt: the number of pci devices have the same PCI subname + :param bdf: it is a string what contains BDF + :param subname: it is a string belong to PIC subname + :param config: it is a file pointer of pci information for writing to + """ # if there is only one host bridge, then will discard the index of suffix if i_cnt == 0 and subname.upper() == "HOST BRIDGE": tmp_sub_name = "_".join(subname.split()).upper() @@ -84,7 +89,11 @@ def write_pbdf(i_cnt, bdf, subname, config): def write_vbar(bdf, pci_bar_dic, config): - """Parser and generate vbar""" + """Parser and generate vbar + :param bdf: it is a string what contains BDF + :param pci_bar_dic: it is a dictionary of pci vbar for those BDF + :param config: it is a file pointer of pci information for writing to + """ tail = 0 align = ' ' * 48 if bdf in pci_bar_dic.keys(): @@ -110,7 +119,9 @@ def write_vbar(bdf, pci_bar_dic, config): def generate_file(config): - """Get PCI device and generate pci_devices.h""" + """Get PCI device and generate pci_devices.h + :param config: it is a file pointer of pci information for writing to + """ # write the license into pci print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config) diff --git a/misc/acrn-config/target/acpi.py b/misc/acrn-config/target/acpi.py index 40843fc51..d6f4d69ee 100644 --- a/misc/acrn-config/target/acpi.py +++ b/misc/acrn-config/target/acpi.py @@ -123,32 +123,43 @@ PackedCx = GasType def store_cpu_info(sysnode, config): - """This will get CPU information from /proc/cpuifo""" + """This will get CPU information + :param sysnode: the path to get cpu information, like: /proc/cpuifo + :param config: file pointer that opened for writing board config information + """ with open(sysnode, 'r') as f_node: line = f_node.readline() while line: if len(line.split(':')) >= 2: if line.split(':')[0].strip() == "model name": model_name = line.split(':')[1].strip() - print('\t\t"{0}"'.format(model_name), file=config) + print('\t"{0}"'.format(model_name), file=config) break line = f_node.readline() -def write_reset_reg(space_id, rst_reg_addr, rst_reg_space_id, rst_reg_val, config): - """Write reset register info""" +def write_reset_reg(rst_reg_addr, rst_reg_space_id, rst_reg_val, config): + """Write reset register info + :param rst_reg_addr: reset register address + :param rst_reg_space_id: reset register space id + :param rst_reg_val: reset register value + :param config: file pointer that opened for writing board config information + """ print("\t{0}".format(""), file=config) print("\t#define RESET_REGISTER_ADDRESS 0x{:0>2X}UL".format( rst_reg_addr), file=config) print("\t#define RESET_REGISTER_SPACE_ID {0}".format( - space_id[rst_reg_space_id]), file=config) + SPACE_ID[rst_reg_space_id]), file=config) print("\t#define RESET_REGISTER_VALUE {0}U".format( rst_reg_val), file=config) print("\t{0}\n".format(""), file=config) def get_vector_reset(sysnode, config): - """This will get reset reg value""" + """This will get reset register value + :param sysnode: the system node of Px power state, like:/sys/firmware/acpi/tables/FACP + :param config: file pointer that opened for writing board config information + """ reset_reg = ResetReg() for key, offset in FACP_OFF.items(): with open(sysnode, 'rb') as f_node: @@ -171,12 +182,15 @@ def get_vector_reset(sysnode, config): packed_data = f_node.read(1) reset_reg.reset_reg_val = hex(packed_data[0]) - write_reset_reg(SPACE_ID, reset_reg.reset_reg_addr, reset_reg.reset_reg_space_id, + write_reset_reg(reset_reg.reset_reg_addr, reset_reg.reset_reg_space_id, reset_reg.reset_reg_val, config) def read_pm_sstate(sysnode, config): - """This will read Px state of power""" + """This will read Px state of power + :param sysnode: the system node of Px power state, like:/sys/firmware/acpi/tables/FACP + :param config: file pointer that opened for writing board config information + """ get_vector_reset(sysnode, config) print("\t{0}".format(""), file=config) for key, offset in FACP_OFF.items(): @@ -238,7 +252,10 @@ def read_pm_sstate(sysnode, config): def if_sx_name(sx_name, f_node): - """If sx name in this field""" + """If sx name in this field + :param sx_name: Sx name in DSDT of apci table, like _s3_, _s5_ + :param f_node: f_node: file pointer that opened for reading sx from + """ need_break = need_continue = 0 name_buf = f_node.read(4) if not name_buf: @@ -260,7 +277,10 @@ def if_sx_name(sx_name, f_node): def read_sx_locate(sx_name, f_node): - """Read the location of sx""" + """Read the location of sx + :param sx_name: Sx name in DSDT of apci table, like _s3_, _s5_ + :param f_node: file pointer that opened for sx reading from + """ need_continue = need_break = pkg_len = 0 (need_break, need_continue) = if_sx_name(sx_name, f_node) @@ -285,7 +305,10 @@ def read_sx_locate(sx_name, f_node): def decode_sx_pkg(pkg_len, f_node): - """Parser and decode the sx pkg""" + """Parser and decode the sx pkg + :param pkg_len: the length of sx package read from f_node + :param f_node: file pointer that opened for sx reading from + """ pkg_val_pm1a = pkg_val_pm1b = pkg_val_resv = need_break = 0 pkg_buf = f_node.read(int.from_bytes(pkg_len, 'little')) if hex(pkg_buf[1]) == ACPI_OP['AML_ZERO_OP'] or \ @@ -321,7 +344,11 @@ def decode_sx_pkg(pkg_len, f_node): def read_pm_sdata(sysnode, sx_name, config): - """This will read pm Sx state of power""" + """This will read pm Sx state of power + :param sysnode: the system node of Sx power state, like:/sys/firmware/acpi/tables/DSDT + :param sx_name: Sx name in DSDT of apci table, like _s3_, _s5_ + :param config: file pointer that opened for writing board config information + """ with open(sysnode, 'rb') as f_node: while True: inc = f_node.read(1) @@ -368,7 +395,11 @@ def read_pm_sdata(sysnode, sx_name, config): def store_cx_data(sysnode1, sysnode2, config): - """This will get Cx data of power and store it to PackedCx""" + """This will get Cx data of power and store it to PackedCx + :param sysnode1: the path of cx power state driver + :param sysnode2: the path of cpuidle + :param config: file pointer that opened for writing board config information + """ i = 0 state_cpus = {} with open(sysnode1, 'r') as acpi_idle: @@ -394,6 +425,7 @@ def store_cx_data(sysnode1, sysnode2, config): acpi_hw_type = ['HLT', 'MWAIT', 'IOPORT'] cx_state = defaultdict(dict) + c_cnt = 1 for state in state_cpus: i += 1 for item in cpu_state: @@ -420,17 +452,21 @@ def store_cx_data(sysnode1, sysnode2, config): PackedCx.bit_offset_8b = 0 PackedCx.access_size_8b = 0 PackedCx.address_64b = cx_state[state][cpu_state[0]].split()[2] - print("\t\t{{{{{}, 0x{:0>2X}U, 0x{:0>2X}U, 0x{:0>2X}U, ".format( + print("\t{{{{{}, 0x{:0>2X}U, 0x{:0>2X}U, 0x{:0>2X}U, ".format( PackedCx.space_id_8b, PackedCx.bit_width_8b, PackedCx.bit_offset_8b, PackedCx.access_size_8b), file=config, end="") - print("0x{:0>2X}UL}}, 0x{:0>2X}U, 0x{:0>2X}U, 0x{:0>2X}U}},".format( + print("0x{:0>2X}UL}}, 0x{:0>2X}U, 0x{:0>2X}U, 0x{:0>2X}U}},\t/* C{} */".format( int(str(PackedCx.address_64b), 16), cx_state[state]['type'], int(cx_state[state][cpu_state[1]]), - int(cx_state[state][cpu_state[2]])), file=config) + int(cx_state[state][cpu_state[2]]), c_cnt), file=config) + c_cnt += 1 def store_px_data(sysnode, config): - """This will get Px data of power and store it to px data""" + """This will get Px data of power and store it to px data + :param sysnode: the path of system power state, such as: /sys/devices/system/cpu/ + :param config: file pointer that opened for writing board config information + """ px_tmp = PxPkg() px_data = {} with open(sysnode+'cpu0/cpufreq/scaling_driver', 'r') as f_node: @@ -483,47 +519,51 @@ def store_px_data(sysnode, config): px_tmp.control = ctl_state px_tmp.status = ctl_state px_data[freq] = px_tmp - print("\t\t{{0x{:0>2X}UL, 0x{:0>2X}UL, 0x{:0>2X}UL, ".format( + print("\t{{0x{:0>2X}UL, 0x{:0>2X}UL, 0x{:0>2X}UL, ".format( px_data[freq].core_freq, px_data[freq].power, px_data[freq].trans_latency), file=config, end="") - print("0x{:0>2X}UL, 0x{:0>6X}UL, 0x{:0>6X}UL}}, /* P{} */".format( + print("0x{:0>2X}UL, 0x{:0>6X}UL, 0x{:0>6X}UL}},\t/* P{} */".format( px_data[freq].bus_latency, px_data[freq].control, px_data[freq].status, p_cnt), file=config) p_cnt += 1 -def gen_acpi_info(board_fp): - """This will parser the sys node form SYS_PATH and generate ACPI info""" - read_pm_sstate(SYS_PATH[1] + 'FACP', board_fp) +def gen_acpi_info(config): + """This will parser the sys node form SYS_PATH and generate ACPI info + :param config: file pointer that opened for writing board config information + """ + read_pm_sstate(SYS_PATH[1] + 'FACP', config) - print("{0}".format("\t"), file=board_fp) - read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S3_', board_fp) - print("{0}".format("\t\n"), file=board_fp) + print("{0}".format("\t"), file=config) + read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S3_', config) + print("{0}".format("\t\n"), file=config) - print("{0}".format("\t"), file=board_fp) - read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S5_', board_fp) - print("{0}".format("\t\n"), file=board_fp) + print("{0}".format("\t"), file=config) + read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S5_', config) + print("{0}".format("\t\n"), file=config) - print("{0}".format("\t"), file=board_fp) - dmar.write_dmar_data(SYS_PATH[1] + 'DMAR', board_fp) - print("{0}".format("\t\n"), file=board_fp) + print("{0}".format("\t"), file=config) + dmar.write_dmar_data(SYS_PATH[1] + 'DMAR', config) + print("{0}".format("\t\n"), file=config) - print("{0}".format("\t"), file=board_fp) - store_cpu_info(SYS_PATH[0], board_fp) - print("{0}".format("\t\n"), file=board_fp) + print("{0}".format("\t"), file=config) + store_cpu_info(SYS_PATH[0], config) + print("{0}".format("\t\n"), file=config) - print("{0}".format("\t"), file=board_fp) - store_cx_data(SYS_PATH[2]+'cpuidle/current_driver', SYS_PATH[2]+'cpu0/cpuidle/', board_fp) - print("{0}".format("\t\n"), file=board_fp) + print("{0}".format("\t"), file=config) + store_cx_data(SYS_PATH[2]+'cpuidle/current_driver', SYS_PATH[2]+'cpu0/cpuidle/', config) + print("{0}".format("\t\n"), file=config) - print("{0}".format("\t"), file=board_fp) - store_px_data(SYS_PATH[2], board_fp) - print("{0}".format("\t\n"), file=board_fp) + print("{0}".format("\t"), file=config) + store_px_data(SYS_PATH[2], config) + print("{0}".format("\t\n"), file=config) def generate_info(board_file): - """This will generate ACPI info from board file""" + """This will generate ACPI info from board file + :param board_file: this is the file which stores the hardware board information + """ # Generate board info - with open(board_file, 'a+') as board_info: - gen_acpi_info(board_info) + with open(board_file, 'a+') as config: + gen_acpi_info(config) diff --git a/misc/acrn-config/target/board_parser.py b/misc/acrn-config/target/board_parser.py index 99e76100b..e83e1236d 100755 --- a/misc/acrn-config/target/board_parser.py +++ b/misc/acrn-config/target/board_parser.py @@ -8,17 +8,18 @@ import sys import shutil import argparse import subprocess -import parser_lib import pci_dev import dmi import acpi import clos +import misc +import parser_lib OUTPUT = "./out/" PY_CACHE = "__pycache__" # This file store information which query from hw board -BIN_LIST = ['cpuid', 'rdmsr', 'lspci', ' dmidecode'] +BIN_LIST = ['cpuid', 'rdmsr', 'lspci', ' dmidecode', 'blkid'] PCI_IDS = ["/usr/share/hwdata/pci.ids", "/usr/share/misc/pci.ids"] CPU_VENDOR = "GenuineIntel" @@ -57,7 +58,7 @@ def vendor_check(): if len(line.split(':')) == 2: if line.split(':')[0].strip() == "vendor_id": vendor_name = line.split(':')[1].strip() - return vendor_name != CPU_VENDOR + return vendor_name == CPU_VENDOR def check_env(): @@ -66,7 +67,7 @@ def check_env(): shutil.rmtree(PY_CACHE) # check cpu vendor id - if vendor_check(): + if not vendor_check(): parser_lib.print_red("Please run this tools on {}!".format(CPU_VENDOR)) sys.exit(1) @@ -91,7 +92,6 @@ def check_env(): parser_lib.print_yel("Need CPUID version >= 20170122") sys.exit(1) - if not native_check(): parser_lib.print_red("Please run this tools on natvie OS!") sys.exit(1) @@ -136,6 +136,9 @@ if __name__ == '__main__': # Generate clos info clos.generate_info(BOARD_INFO) + # Generate misc info + misc.generate_info(BOARD_INFO) + with open(BOARD_INFO, 'a+') as f: print("", file=f) diff --git a/misc/acrn-config/target/clos.py b/misc/acrn-config/target/clos.py index 15400c6f1..4fccfb35a 100644 --- a/misc/acrn-config/target/clos.py +++ b/misc/acrn-config/target/clos.py @@ -11,8 +11,11 @@ CACHE_TYPE = { } -def execute(cmd, reg): - """Execute the cmd""" +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_excute(cmd) @@ -55,7 +58,7 @@ def get_clos_info(): clos_max = 0 clos_cache = False cmd = "cpuid -r -l 0x10" - clos_cache = execute(cmd, "ebx") + clos_cache = dump_cpuid_reg(cmd, "ebx") if clos_cache == "L2": cmd = "cpuid -r -l 0x10 --subleaf 2" @@ -66,16 +69,19 @@ def get_clos_info(): parser_lib.print_yel("CLOS is not supported!") return (clos_cache, clos_max) - clos_max = execute(cmd, "edx") + clos_max = dump_cpuid_reg(cmd, "edx") return (clos_cache, clos_max) + def generate_info(board_info): - """Generate clos information""" + """Generate clos information + :param board_info: this is the file which stores the hardware board information + """ (clos_cache, clos_max) = get_clos_info() - with open(board_info, 'a+') as board_fp: - print("\t", file=board_fp) - print("\tclos supported by cache:{}".format(clos_cache), file=board_fp) - print("\tclos max:{}".format(clos_max), file=board_fp) - print("\t\n", file=board_fp) + with open(board_info, 'a+') as config: + print("\t", file=config) + print("\tclos supported by cache:{}".format(clos_cache), file=config) + print("\tclos max:{}".format(clos_max), file=config) + print("\t\n", file=config) diff --git a/misc/acrn-config/target/dmar.py b/misc/acrn-config/target/dmar.py index fc348dd77..01d9be1b8 100644 --- a/misc/acrn-config/target/dmar.py +++ b/misc/acrn-config/target/dmar.py @@ -203,7 +203,13 @@ class PathDevFun: def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, n_cnt, drhd_cnt): - """Walk Pci bus""" + """Walk Pci bus + :param tmp_pdf: it is a class what contains path,device,function in dmar device scope region + :param dmar_tbl: it is a class to describe dmar which contains Device Scope and DRHD + :param dmar_hw_list: it is a class to describe hardware scope in DMAR table + :param n_cnt: the number of device in device scope + :param drhd_cnt: it is a counter to calculate the DRHD in DMAR table + """ while n_cnt: scope_path = DevScopePath.from_address(dmar_tbl.path_offset) tmp_pdf.device = scope_path.device @@ -223,7 +229,12 @@ def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, n_cnt, drhd_cnt): def walk_dev_scope(dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt): - """Walk device scope""" + """Walk device scope + :param dmar_tbl: it is a class to describe dmar which contains Device Scope and DRHD + :param dmar_dev_list: it is a class to describe device scope in DMAR table + :param dmar_hw_list: it is a class to describe DRHD in DMAR table + :param drhd_cnt: it is a counter to calculate the DRHD in DMAR table + """ dmar_tbl.dev_scope_offset = dmar_tbl.sub_tbl_offset + ctypes.sizeof(DmarHwUnit) scope_end = dmar_tbl.dev_scope_offset + dmar_tbl.dmar_drhd.sub_header.length dmar_tbl.dev_scope_cnt = 0 @@ -259,7 +270,12 @@ def walk_dev_scope(dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt): def walk_dmar_table(dmar_tbl, dmar_hw_list, dmar_dev_list, sysnode): - """Walk dmar table and get information""" + """Walk dmar table and get information + :param dmar_tbl: it is a class to describe dmar which contains Device Scope and DRHD + :param dmar_hw_list: it is a class to describe hardware scope in DMAR table + :param dmar_dev_list: it is a class to describe device scope in DMAR table + :param sysnode: the system device node of acpi table, such as: /sys/firmware/acpi/tables/DMAR + """ data = open(sysnode, 'rb').read() buf = ctypes.create_string_buffer(data, len(data)) addr = ctypes.addressof(buf) @@ -289,7 +305,7 @@ def walk_dmar_table(dmar_tbl, dmar_hw_list, dmar_dev_list, sysnode): dmar_hw_list.hw_flags_list.append(dmar_tbl.dmar_drhd.flags) dmar_hw_list.hw_address_list.append(dmar_tbl.dmar_drhd.address) - # in end of DRHD/sub tbl header is devscope + # in end of DRHD/sub tbl header is dev scope, then enumerate the device scope (dmar_tbl, dmar_dev_list, dmar_hw_list) = walk_dev_scope( dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt) @@ -301,7 +317,10 @@ def walk_dmar_table(dmar_tbl, dmar_hw_list, dmar_dev_list, sysnode): def write_dmar_data(sysnode, config): - """Write the DMAR data to board info""" + """Write the DMAR data to board info + :param sysnode: the system device node of acpi table, such as: /sys/firmware/acpi/tables/DMAR + :param config: file pointer that opened for writing board information + """ dmar_hw_list = DmarHwList() dmar_dev_list = DmarDevList() diff --git a/misc/acrn-config/target/dmi.py b/misc/acrn-config/target/dmi.py index 7f1b393ae..243b8ad78 100644 --- a/misc/acrn-config/target/dmi.py +++ b/misc/acrn-config/target/dmi.py @@ -12,9 +12,11 @@ CMDS = { def generate_info(board_info): - """Get bios and base board information""" + """Get bios and base board information + :param board_info: this is the file which stores the hardware board information + """ with open(board_info, 'a+') as config: - parser_lib.dump_excute(CMDS['BIOS_INFO'], 'BIOS_INFO', config) + parser_lib.dump_execute(CMDS['BIOS_INFO'], 'BIOS_INFO', config) print("", file=config) - parser_lib.dump_excute(CMDS['BASE_BOARD_INFO'], 'BASE_BOARD_INFO', config) + parser_lib.dump_execute(CMDS['BASE_BOARD_INFO'], 'BASE_BOARD_INFO', config) print("", file=config) diff --git a/misc/acrn-config/target/misc.py b/misc/acrn-config/target/misc.py new file mode 100644 index 000000000..f5c5161e4 --- /dev/null +++ b/misc/acrn-config/target/misc.py @@ -0,0 +1,50 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +import parser_lib + +IO_MEM_PATH = '/proc/iomem' + + +def get_system_ram(config): + """This will get systemd ram which are usable + :param config: file pointer that opened for writing board config information + """ + print("\t", file=config) + with open(IO_MEM_PATH, 'rt') as mem_info: + + while True: + line = mem_info.readline().strip() + if not line: + break + + pat_type = line.split(':')[1].strip() + if pat_type == "System RAM": + print("\t{}".format(line), file=config) + + print("\t", file=config) + print("", file=config) + + +def get_root_dev(config): + """This will get available root device + :param config: file pointer that opened for writing board config information + """ + cmd = 'blkid' + desc = 'ROOT_DEVICE_INFO' + parser_lib.dump_execute(cmd, desc, config) + print("", file=config) + + +def generate_info(board_info): + """Get System Ram information + :param board_info: this is the file which stores the hardware board information + """ + with open(board_info, 'a+') as config: + + get_system_ram(config) + + get_root_dev(config) + diff --git a/misc/acrn-config/target/parser_lib.py b/misc/acrn-config/target/parser_lib.py index 9253b8551..f81fe2fc6 100644 --- a/misc/acrn-config/target/parser_lib.py +++ b/misc/acrn-config/target/parser_lib.py @@ -17,7 +17,10 @@ def check_dmi(): def print_yel(msg, warn=False): - """Print the msg wiht color of yellow""" + """Output the message with the color of yellow + :param msg: the stings which will be output to STDOUT + :param warn: the condition if needs to be output the color of yellow with 'Warning' + """ if warn: print("\033[1;33mWarning\033[0m:"+msg) else: @@ -25,7 +28,10 @@ def print_yel(msg, warn=False): def print_red(msg, err=False): - """Print the msg wiht color of red""" + """Output the messag with the color of red + :param msg: the stings which will be output to STDOUT + :param err: the condition if needs to be output the color of red with 'Error' + """ if err: print("\033[1;31mError\033[0m:"+msg) else: @@ -33,13 +39,18 @@ def print_red(msg, err=False): def decode_stdout(resource): - """Decode stdout""" + """Decode the information and return one line of the decoded information + :param resource: it contains information produced by subprocess.Popen method + """ line = resource.stdout.readline().decode('ascii') return line def handle_hw_info(line, hw_info): - """handle the hardware information""" + """Handle the hardware information + :param line: one line of information which had decoded to 'ASCII' + :param hw_info: the list which contains key strings what can describe bios/board + """ for board_line in hw_info: if board_line == " ".join(line.split()[0:1]) or \ board_line == " ".join(line.split()[0:2]) or \ @@ -49,7 +60,9 @@ def handle_hw_info(line, hw_info): def handle_pci_dev(line): - """Handle if it is pci line""" + """Handle if it match PCI device information pattern + :param line: one line of information which had decoded to 'ASCII' + """ if "Region" in line and "Memory at" in line: return True @@ -61,15 +74,32 @@ def handle_pci_dev(line): def cmd_excute(cmd): - """Excute cmd and retrun raw""" + """Excute cmd and retrun raw information + :param cmd: command what can be executed in shell + """ res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) return res -def dump_excute(cmd, desc, config): - """Execute cmd and get information""" +def handle_root_dev(line): + """Handle if it match root device information pattern + :param line: one line of information which had decoded to 'ASCII' + """ + for root_type in line.split(): + if "ext4" in root_type or "ext3" in root_type: + return True + + return False + + +def dump_execute(cmd, desc, config): + """Execute cmd and get information + :param cmd: command what can be executed in shell + :param desc: the string indicated what class information store to board.xml + :param config: file pointer that opened for writing board information + """ val_dmi = check_dmi() print("\t<{0}>".format(desc), file=config) @@ -101,6 +131,11 @@ def dump_excute(cmd, desc, config): if not ret: continue + if desc == "ROOT_DEVICE_INFO": + ret = handle_root_dev(line) + if not ret: + continue + print("\t{}".format(line.strip()), file=config) print("\t".format(desc), file=config) diff --git a/misc/acrn-config/target/pci_dev.py b/misc/acrn-config/target/pci_dev.py index cd31a8ce6..e28c953fe 100644 --- a/misc/acrn-config/target/pci_dev.py +++ b/misc/acrn-config/target/pci_dev.py @@ -12,9 +12,11 @@ CMDS = { def generate_info(board_info): - """Get the pci info""" + """Get the pci info + :param board_info: this is the file which stores the hardware board information + """ with open(board_info, 'a+') as config: - parser_lib.dump_excute(CMDS['PCI_DEVICE'], 'PCI_DEVICE', config) + parser_lib.dump_execute(CMDS['PCI_DEVICE'], 'PCI_DEVICE', config) print("", file=config) - parser_lib.dump_excute(CMDS['PCI_VID_PID'], 'PCI_VID_PID', config) + parser_lib.dump_execute(CMDS['PCI_VID_PID'], 'PCI_VID_PID', config) print("", file=config)