acrn-config: enhance the target config

1. add misc.py to get systemd ram and root device
2. add more specify comments for arguments of functions

v1-v2:
    typo: Parser -> Parse
    some grammar check

v2-v3:
    add the message for Cx state

Tracked-On: #3602
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
Acked-by: Terry Zou <terry.zou@intel.com>
Acked-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Wei Liu 2019-08-02 19:17:58 +08:00 committed by wenlingz
parent a95a88c5b2
commit 77c17ab479
13 changed files with 317 additions and 102 deletions

View File

@ -31,7 +31,12 @@ class OverridAccessSize():
def multi_parser(line, s_line, pm_ac_sz, config): 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'] 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'] 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): 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'] write_direct = ['PM1A_EVT_ACCESS_SIZE', 'PM1A_EVT_ADDRESS', 'PM1A_CNT_ADDRESS']
pm_ac_sz = OverridAccessSize() 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): 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) vector_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, msg_s, msg_e)
for vector in vector_lines: for vector in vector_lines:
@ -109,7 +123,9 @@ def write_direct_info_parser(config, msg_s, msg_e):
def drhd_info_parser(config): 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 prev_num = 0
drhd_lines = board_cfg_lib.get_info( drhd_lines = board_cfg_lib.get_info(
@ -133,7 +149,10 @@ def drhd_info_parser(config):
def platform_info_parser(config, default_platform): 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) print("\n/* pm sstate data */", file=config)
multi_info_parser(config, default_platform, "<PM_INFO>", "</PM_INFO>") multi_info_parser(config, default_platform, "<PM_INFO>", "</PM_INFO>")
multi_info_parser(config, default_platform, "<S3_INFO>", "</S3_INFO>") multi_info_parser(config, default_platform, "<S3_INFO>", "</S3_INFO>")
@ -146,7 +165,10 @@ def platform_info_parser(config, default_platform):
def generate_file(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(board_cfg_lib.HEADER_LICENSE), file=config)
print("{}".format(PLATFORM_HEADER), file=config) print("{}".format(PLATFORM_HEADER), file=config)

View File

@ -26,7 +26,9 @@ def clos_info_parser():
def gen_cat(config): 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() (cache_support, clos_max) = clos_info_parser()
print("\n#include <board.h>", file=config) print("\n#include <board.h>", file=config)
@ -48,7 +50,8 @@ def gen_cat(config):
elif cache_support == "L3": elif cache_support == "L3":
print("\t\t.msr_index = {0}U,".format(hex(0x00000C90+i_cnt)), file=config) print("\t\t.msr_index = {0}U,".format(hex(0x00000C90+i_cnt)), file=config)
else: 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) sys.exit(1)
print("\t},", file=config) print("\t},", file=config)
@ -61,7 +64,9 @@ def gen_cat(config):
def gen_px_cx(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( cpu_brand_lines = board_cfg_lib.get_info(
board_cfg_lib.BOARD_INFO_FILE, "<CPU_BRAND>", "</CPU_BRAND>") board_cfg_lib.BOARD_INFO_FILE, "<CPU_BRAND>", "</CPU_BRAND>")
cx_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<CX_INFO>", "</CX_INFO>") cx_lines = board_cfg_lib.get_info(board_cfg_lib.BOARD_INFO_FILE, "<CX_INFO>", "</CX_INFO>")
@ -92,7 +97,9 @@ def gen_px_cx(config):
def generate_file(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) print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
# insert bios info into board.c # insert bios info into board.c

View File

@ -54,7 +54,10 @@ def prepare():
def gen_patch(srcs_list, board_name): 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) changes = ' '.join(srcs_list)
git_add = "git add {}".format(changes) git_add = "git add {}".format(changes)
subprocess.call(git_add, shell=True, stdout=subprocess.PIPE, 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): 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 = '' board = ''
config_srcs = [] config_srcs = []
config_dirs = [] config_dirs = []
@ -101,7 +106,7 @@ def main(board_info_file):
with open(config_platform, 'w+') as config: with open(config_platform, 'w+') as config:
acpi_platform_h.generate_file(config, ACRN_DEFAULT_PLATFORM) 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) gen_patch(config_srcs, board)
if board not in BOARD_NAMES: 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)) board_cfg_lib.print_red("{} is not exist!".format(BOARD_INFO_FILE))
sys.exit(1) sys.exit(1)
# board_info.txt will be override
board_cfg_lib.BOARD_INFO_FILE = BOARD_INFO_FILE board_cfg_lib.BOARD_INFO_FILE = BOARD_INFO_FILE
main(BOARD_INFO_FILE) main(BOARD_INFO_FILE)

View File

@ -28,7 +28,10 @@ HEADER_LICENSE = open_license() + "\n"
def print_yel(msg, warn=False): 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: if warn:
print("\033[1;33mWarning\033[0m:"+msg) print("\033[1;33mWarning\033[0m:"+msg)
else: else:
@ -36,7 +39,10 @@ def print_yel(msg, warn=False):
def print_red(msg, err=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: if err:
print("\033[1;31mError\033[0m:"+msg) print("\033[1;31mError\033[0m:"+msg)
else: else:
@ -44,7 +50,9 @@ def print_red(msg, err=False):
def get_board_name(board_info): 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: with open(board_info, 'rt') as f_board:
line = f_board.readline() line = f_board.readline()
if not "board=" in line: if not "board=" in line:
@ -56,7 +64,11 @@ def get_board_name(board_info):
def get_info(board_info, msg_s, msg_e): 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_start = False
info_end = False info_end = False
info_lines = [] info_lines = []
@ -93,7 +105,9 @@ def get_info(board_info, msg_s, msg_e):
def handle_bios_info(config): 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, "<BIOS_INFO>", "</BIOS_INFO>") bios_lines = get_info(BOARD_INFO_FILE, "<BIOS_INFO>", "</BIOS_INFO>")
board_lines = get_info(BOARD_INFO_FILE, "<BASE_BOARD_INFO>", "</BASE_BOARD_INFO>") board_lines = get_info(BOARD_INFO_FILE, "<BASE_BOARD_INFO>", "</BASE_BOARD_INFO>")
print("/*", file=config) print("/*", file=config)
@ -116,9 +130,9 @@ def handle_bios_info(config):
i_cnt += 1 i_cnt += 1
for mics_info in bios_board_info: for misc_info in bios_board_info:
if mics_info == " ".join(line.split()[0:1]) or mics_info == \ if misc_info == " ".join(line.split()[0:1]) or misc_info == \
" ".join(line.split()[0:2]) or mics_info == " ".join(line.split()[0:3]): " ".join(line.split()[0:2]) or misc_info == " ".join(line.split()[0:3]):
print(" * {0}".format(line.strip()), file=config) print(" * {0}".format(line.strip()), file=config)
print(" */", file=config) print(" */", file=config)

View File

@ -68,7 +68,12 @@ def parser_pci():
def write_pbdf(i_cnt, bdf, subname, config): 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 there is only one host bridge, then will discard the index of suffix
if i_cnt == 0 and subname.upper() == "HOST BRIDGE": if i_cnt == 0 and subname.upper() == "HOST BRIDGE":
tmp_sub_name = "_".join(subname.split()).upper() 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): 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 tail = 0
align = ' ' * 48 align = ' ' * 48
if bdf in pci_bar_dic.keys(): if bdf in pci_bar_dic.keys():
@ -110,7 +119,9 @@ def write_vbar(bdf, pci_bar_dic, config):
def generate_file(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 # write the license into pci
print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config) print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)

View File

@ -123,32 +123,43 @@ PackedCx = GasType
def store_cpu_info(sysnode, config): 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: with open(sysnode, 'r') as f_node:
line = f_node.readline() line = f_node.readline()
while line: while line:
if len(line.split(':')) >= 2: if len(line.split(':')) >= 2:
if line.split(':')[0].strip() == "model name": if line.split(':')[0].strip() == "model name":
model_name = line.split(':')[1].strip() model_name = line.split(':')[1].strip()
print('\t\t"{0}"'.format(model_name), file=config) print('\t"{0}"'.format(model_name), file=config)
break break
line = f_node.readline() line = f_node.readline()
def write_reset_reg(space_id, rst_reg_addr, rst_reg_space_id, rst_reg_val, config): def write_reset_reg(rst_reg_addr, rst_reg_space_id, rst_reg_val, config):
"""Write reset register info""" """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("<RESET_REGISTER_INFO>"), file=config) print("\t{0}".format("<RESET_REGISTER_INFO>"), file=config)
print("\t#define RESET_REGISTER_ADDRESS 0x{:0>2X}UL".format( print("\t#define RESET_REGISTER_ADDRESS 0x{:0>2X}UL".format(
rst_reg_addr), file=config) rst_reg_addr), file=config)
print("\t#define RESET_REGISTER_SPACE_ID {0}".format( 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( print("\t#define RESET_REGISTER_VALUE {0}U".format(
rst_reg_val), file=config) rst_reg_val), file=config)
print("\t{0}\n".format("</RESET_REGISTER_INFO>"), file=config) print("\t{0}\n".format("</RESET_REGISTER_INFO>"), file=config)
def get_vector_reset(sysnode, 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() reset_reg = ResetReg()
for key, offset in FACP_OFF.items(): for key, offset in FACP_OFF.items():
with open(sysnode, 'rb') as f_node: with open(sysnode, 'rb') as f_node:
@ -171,12 +182,15 @@ def get_vector_reset(sysnode, config):
packed_data = f_node.read(1) packed_data = f_node.read(1)
reset_reg.reset_reg_val = hex(packed_data[0]) 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) reset_reg.reset_reg_val, config)
def read_pm_sstate(sysnode, 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) get_vector_reset(sysnode, config)
print("\t{0}".format("<PM_INFO>"), file=config) print("\t{0}".format("<PM_INFO>"), file=config)
for key, offset in FACP_OFF.items(): 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): 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 need_break = need_continue = 0
name_buf = f_node.read(4) name_buf = f_node.read(4)
if not name_buf: if not name_buf:
@ -260,7 +277,10 @@ def if_sx_name(sx_name, f_node):
def read_sx_locate(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_continue = need_break = pkg_len = 0
(need_break, need_continue) = if_sx_name(sx_name, f_node) (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): 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_val_pm1a = pkg_val_pm1b = pkg_val_resv = need_break = 0
pkg_buf = f_node.read(int.from_bytes(pkg_len, 'little')) pkg_buf = f_node.read(int.from_bytes(pkg_len, 'little'))
if hex(pkg_buf[1]) == ACPI_OP['AML_ZERO_OP'] or \ 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): 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: with open(sysnode, 'rb') as f_node:
while True: while True:
inc = f_node.read(1) inc = f_node.read(1)
@ -368,7 +395,11 @@ def read_pm_sdata(sysnode, sx_name, config):
def store_cx_data(sysnode1, sysnode2, 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 i = 0
state_cpus = {} state_cpus = {}
with open(sysnode1, 'r') as acpi_idle: with open(sysnode1, 'r') as acpi_idle:
@ -394,6 +425,7 @@ def store_cx_data(sysnode1, sysnode2, config):
acpi_hw_type = ['HLT', 'MWAIT', 'IOPORT'] acpi_hw_type = ['HLT', 'MWAIT', 'IOPORT']
cx_state = defaultdict(dict) cx_state = defaultdict(dict)
c_cnt = 1
for state in state_cpus: for state in state_cpus:
i += 1 i += 1
for item in cpu_state: for item in cpu_state:
@ -420,17 +452,21 @@ def store_cx_data(sysnode1, sysnode2, config):
PackedCx.bit_offset_8b = 0 PackedCx.bit_offset_8b = 0
PackedCx.access_size_8b = 0 PackedCx.access_size_8b = 0
PackedCx.address_64b = cx_state[state][cpu_state[0]].split()[2] 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.space_id_8b, PackedCx.bit_width_8b, PackedCx.bit_offset_8b,
PackedCx.access_size_8b), file=config, end="") 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), int(str(PackedCx.address_64b), 16),
cx_state[state]['type'], int(cx_state[state][cpu_state[1]]), 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): 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_tmp = PxPkg()
px_data = {} px_data = {}
with open(sysnode+'cpu0/cpufreq/scaling_driver', 'r') as f_node: 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.control = ctl_state
px_tmp.status = ctl_state px_tmp.status = ctl_state
px_data[freq] = px_tmp 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].core_freq, px_data[freq].power,
px_data[freq].trans_latency), file=config, end="") 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].bus_latency, px_data[freq].control,
px_data[freq].status, p_cnt), file=config) px_data[freq].status, p_cnt), file=config)
p_cnt += 1 p_cnt += 1
def gen_acpi_info(board_fp): def gen_acpi_info(config):
"""This will parser the sys node form SYS_PATH and generate ACPI info""" """This will parser the sys node form SYS_PATH and generate ACPI info
read_pm_sstate(SYS_PATH[1] + 'FACP', board_fp) :param config: file pointer that opened for writing board config information
"""
read_pm_sstate(SYS_PATH[1] + 'FACP', config)
print("{0}".format("\t<S3_INFO>"), file=board_fp) print("{0}".format("\t<S3_INFO>"), file=config)
read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S3_', board_fp) read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S3_', config)
print("{0}".format("\t</S3_INFO>\n"), file=board_fp) print("{0}".format("\t</S3_INFO>\n"), file=config)
print("{0}".format("\t<S5_INFO>"), file=board_fp) print("{0}".format("\t<S5_INFO>"), file=config)
read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S5_', board_fp) read_pm_sdata(SYS_PATH[1] + 'DSDT', '_S5_', config)
print("{0}".format("\t</S5_INFO>\n"), file=board_fp) print("{0}".format("\t</S5_INFO>\n"), file=config)
print("{0}".format("\t<DRHD_INFO>"), file=board_fp) print("{0}".format("\t<DRHD_INFO>"), file=config)
dmar.write_dmar_data(SYS_PATH[1] + 'DMAR', board_fp) dmar.write_dmar_data(SYS_PATH[1] + 'DMAR', config)
print("{0}".format("\t</DRHD_INFO>\n"), file=board_fp) print("{0}".format("\t</DRHD_INFO>\n"), file=config)
print("{0}".format("\t<CPU_BRAND>"), file=board_fp) print("{0}".format("\t<CPU_BRAND>"), file=config)
store_cpu_info(SYS_PATH[0], board_fp) store_cpu_info(SYS_PATH[0], config)
print("{0}".format("\t</CPU_BRAND>\n"), file=board_fp) print("{0}".format("\t</CPU_BRAND>\n"), file=config)
print("{0}".format("\t<CX_INFO>"), file=board_fp) print("{0}".format("\t<CX_INFO>"), file=config)
store_cx_data(SYS_PATH[2]+'cpuidle/current_driver', SYS_PATH[2]+'cpu0/cpuidle/', board_fp) store_cx_data(SYS_PATH[2]+'cpuidle/current_driver', SYS_PATH[2]+'cpu0/cpuidle/', config)
print("{0}".format("\t</CX_INFO>\n"), file=board_fp) print("{0}".format("\t</CX_INFO>\n"), file=config)
print("{0}".format("\t<PX_INFO>"), file=board_fp) print("{0}".format("\t<PX_INFO>"), file=config)
store_px_data(SYS_PATH[2], board_fp) store_px_data(SYS_PATH[2], config)
print("{0}".format("\t</PX_INFO>\n"), file=board_fp) print("{0}".format("\t</PX_INFO>\n"), file=config)
def generate_info(board_file): 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 # Generate board info
with open(board_file, 'a+') as board_info: with open(board_file, 'a+') as config:
gen_acpi_info(board_info) gen_acpi_info(config)

View File

@ -8,17 +8,18 @@ import sys
import shutil import shutil
import argparse import argparse
import subprocess import subprocess
import parser_lib
import pci_dev import pci_dev
import dmi import dmi
import acpi import acpi
import clos import clos
import misc
import parser_lib
OUTPUT = "./out/" OUTPUT = "./out/"
PY_CACHE = "__pycache__" PY_CACHE = "__pycache__"
# This file store information which query from hw board # 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"] PCI_IDS = ["/usr/share/hwdata/pci.ids", "/usr/share/misc/pci.ids"]
CPU_VENDOR = "GenuineIntel" CPU_VENDOR = "GenuineIntel"
@ -57,7 +58,7 @@ def vendor_check():
if len(line.split(':')) == 2: if len(line.split(':')) == 2:
if line.split(':')[0].strip() == "vendor_id": if line.split(':')[0].strip() == "vendor_id":
vendor_name = line.split(':')[1].strip() vendor_name = line.split(':')[1].strip()
return vendor_name != CPU_VENDOR return vendor_name == CPU_VENDOR
def check_env(): def check_env():
@ -66,7 +67,7 @@ def check_env():
shutil.rmtree(PY_CACHE) shutil.rmtree(PY_CACHE)
# check cpu vendor id # check cpu vendor id
if vendor_check(): if not vendor_check():
parser_lib.print_red("Please run this tools on {}!".format(CPU_VENDOR)) parser_lib.print_red("Please run this tools on {}!".format(CPU_VENDOR))
sys.exit(1) sys.exit(1)
@ -91,7 +92,6 @@ def check_env():
parser_lib.print_yel("Need CPUID version >= 20170122") parser_lib.print_yel("Need CPUID version >= 20170122")
sys.exit(1) sys.exit(1)
if not native_check(): if not native_check():
parser_lib.print_red("Please run this tools on natvie OS!") parser_lib.print_red("Please run this tools on natvie OS!")
sys.exit(1) sys.exit(1)
@ -136,6 +136,9 @@ if __name__ == '__main__':
# Generate clos info # Generate clos info
clos.generate_info(BOARD_INFO) clos.generate_info(BOARD_INFO)
# Generate misc info
misc.generate_info(BOARD_INFO)
with open(BOARD_INFO, 'a+') as f: with open(BOARD_INFO, 'a+') as f:
print("</acrn-config>", file=f) print("</acrn-config>", file=f)

View File

@ -11,8 +11,11 @@ CACHE_TYPE = {
} }
def execute(cmd, reg): def dump_cpuid_reg(cmd, reg):
"""Execute the cmd""" """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 = '' cache_t = ''
res = parser_lib.cmd_excute(cmd) res = parser_lib.cmd_excute(cmd)
@ -55,7 +58,7 @@ def get_clos_info():
clos_max = 0 clos_max = 0
clos_cache = False clos_cache = False
cmd = "cpuid -r -l 0x10" cmd = "cpuid -r -l 0x10"
clos_cache = execute(cmd, "ebx") clos_cache = dump_cpuid_reg(cmd, "ebx")
if clos_cache == "L2": if clos_cache == "L2":
cmd = "cpuid -r -l 0x10 --subleaf 2" cmd = "cpuid -r -l 0x10 --subleaf 2"
@ -66,16 +69,19 @@ def get_clos_info():
parser_lib.print_yel("CLOS is not supported!") parser_lib.print_yel("CLOS is not supported!")
return (clos_cache, clos_max) return (clos_cache, clos_max)
clos_max = execute(cmd, "edx") clos_max = dump_cpuid_reg(cmd, "edx")
return (clos_cache, clos_max) return (clos_cache, clos_max)
def generate_info(board_info): 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() (clos_cache, clos_max) = get_clos_info()
with open(board_info, 'a+') as board_fp: with open(board_info, 'a+') as config:
print("\t<CLOS_INFO>", file=board_fp) print("\t<CLOS_INFO>", file=config)
print("\tclos supported by cache:{}".format(clos_cache), file=board_fp) print("\tclos supported by cache:{}".format(clos_cache), file=config)
print("\tclos max:{}".format(clos_max), file=board_fp) print("\tclos max:{}".format(clos_max), file=config)
print("\t</CLOS_INFO>\n", file=board_fp) print("\t</CLOS_INFO>\n", file=config)

View File

@ -203,7 +203,13 @@ class PathDevFun:
def walk_pci_bus(tmp_pdf, dmar_tbl, dmar_hw_list, n_cnt, drhd_cnt): 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: while n_cnt:
scope_path = DevScopePath.from_address(dmar_tbl.path_offset) scope_path = DevScopePath.from_address(dmar_tbl.path_offset)
tmp_pdf.device = scope_path.device 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): 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) 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 scope_end = dmar_tbl.dev_scope_offset + dmar_tbl.dmar_drhd.sub_header.length
dmar_tbl.dev_scope_cnt = 0 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): 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() data = open(sysnode, 'rb').read()
buf = ctypes.create_string_buffer(data, len(data)) buf = ctypes.create_string_buffer(data, len(data))
addr = ctypes.addressof(buf) 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_flags_list.append(dmar_tbl.dmar_drhd.flags)
dmar_hw_list.hw_address_list.append(dmar_tbl.dmar_drhd.address) 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) = walk_dev_scope(
dmar_tbl, dmar_dev_list, dmar_hw_list, drhd_cnt) 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): 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_hw_list = DmarHwList()
dmar_dev_list = DmarDevList() dmar_dev_list = DmarDevList()

View File

@ -12,9 +12,11 @@ CMDS = {
def generate_info(board_info): 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: 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) 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) print("", file=config)

View File

@ -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<SYSTEM_RAM_INFO>", 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</SYSTEM_RAM_INFO>", 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)

View File

@ -17,7 +17,10 @@ def check_dmi():
def print_yel(msg, warn=False): 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: if warn:
print("\033[1;33mWarning\033[0m:"+msg) print("\033[1;33mWarning\033[0m:"+msg)
else: else:
@ -25,7 +28,10 @@ def print_yel(msg, warn=False):
def print_red(msg, err=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: if err:
print("\033[1;31mError\033[0m:"+msg) print("\033[1;31mError\033[0m:"+msg)
else: else:
@ -33,13 +39,18 @@ def print_red(msg, err=False):
def decode_stdout(resource): 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') line = resource.stdout.readline().decode('ascii')
return line return line
def handle_hw_info(line, hw_info): 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: for board_line in hw_info:
if board_line == " ".join(line.split()[0:1]) or \ if board_line == " ".join(line.split()[0:1]) or \
board_line == " ".join(line.split()[0:2]) 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): 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: if "Region" in line and "Memory at" in line:
return True return True
@ -61,15 +74,32 @@ def handle_pci_dev(line):
def cmd_excute(cmd): 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, res = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
return res return res
def dump_excute(cmd, desc, config): def handle_root_dev(line):
"""Execute cmd and get information""" """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() val_dmi = check_dmi()
print("\t<{0}>".format(desc), file=config) print("\t<{0}>".format(desc), file=config)
@ -101,6 +131,11 @@ def dump_excute(cmd, desc, config):
if not ret: if not ret:
continue 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(line.strip()), file=config)
print("\t</{0}>".format(desc), file=config) print("\t</{0}>".format(desc), file=config)

View File

@ -12,9 +12,11 @@ CMDS = {
def generate_info(board_info): 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: 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) 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) print("", file=config)