def write_pbdf(i_cnt, bdf, bar_attr, config): """ Parser and generate pbdf :param i_cnt: the number of pci devices have the same PCI sub class name :param bdf: it is a string what contains BDF :param bar_attr: it is a class, contains PIC bar attribute :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 bar_attr.name.upper() == "HOST BRIDGE": tmp_sub_name = "_".join(bar_attr.name.split()).upper() else: if '-' in bar_attr.name: tmp_sub_name = common.undline_name( bar_attr.name) + "_" + str(i_cnt) else: tmp_sub_name = "_".join( bar_attr.name.split()).upper() + "_" + str(i_cnt) bus = int(bdf.split(':')[0], 16) dev = int(bdf.split(':')[1].split('.')[0], 16) fun = int(bdf.split('.')[1], 16) print("#define %-32s" % tmp_sub_name, end="", file=config) print( " .pbdf.bits = {{.b = 0x{:02X}U, .d = 0x{:02X}U, .f = 0x{:02X}U}}" .format(bus, dev, fun), end="", file=config) if not bar_attr.remappable: align = ' ' * 48 print("\n{}/* TODO: add {} 64bit BAR support */".format( align, tmp_sub_name), file=config) return
def undline_name(name): """ This convert name which has contain '-' to '_' :param name: name which contain '-' and ' ' :return: name_str which contain'_' """ return common.undline_name(name)
def launch_begin(names, virt_io, vmid, config): board_name = names['board_name'] uos_type = names['uos_types'][vmid] launch_uos = common.undline_name(uos_type).lower() tap_network(virt_io, vmid, config) run_container(board_name, uos_type, config) print("function launch_{}()".format(launch_uos), file=config) print("{", file=config)
def uos_launch(names, args, virt_io, vmid, config): gvt_args = args['gvt_args'][vmid] uos_type = names['uos_types'][vmid] launch_uos = common.undline_name(uos_type).lower() board_name = names['board_name'] if 'nuc' in board_name: board_name = 'nuc' if uos_type == "CLEARLINUX" and board_name in ("apl-mrb", "nuc"): print('if [ "$1" = "-C" ];then', file=config) print(' if [ $(hostname) = "runc" ]; then', file=config) print(' echo "Already in container exit!"', file=config) print(" exit", file=config) print(" fi", file=config) print(' echo "runc_container"', file=config) print(" run_container", file=config) if board_name == "apl-mrb": print(" exit", file=config) print("fi", file=config) else: print("else", file=config) if gvt_args == "gvtd" or not gvt_args: print(' launch_{} {}'.format(launch_uos, vmid), file=config) elif gvt_args: print(' launch_{} {} "{}"'.format(launch_uos, vmid, gvt_args), file=config) print("fi", file=config) else: if uos_type in ("VXWORKS", "PREEMPT-RT LINUX", "ZEPHYR"): print("launch_{} {}".format(launch_uos, vmid), file=config) if uos_type in ("CLEARLINUX", "WINDOWS"): if gvt_args == "gvtd" or not gvt_args: print('launch_{} {}'.format(launch_uos, vmid), file=config) else: print('launch_{} {} "{}"'.format(launch_uos, vmid, gvt_args), file=config) if is_mount_needed(virt_io, vmid): print("", file=config) if gvt_args == "gvtd" or not gvt_args: print('launch_{} {} "{}" $debug'.format(launch_uos, vmid, vmid), file=config) else: print('launch_{} {} "{}" "{}" $debug'.format( launch_uos, vmid, gvt_args, vmid), file=config) print("", file=config) i = 0 for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: if not mount_flag: i += 1 continue print("umount /data{}".format(i), file=config) i += 1
def add_instance_to_name(i_cnt, bdf, bar_attr): if i_cnt == 0 and bar_attr.name.upper() == "HOST BRIDGE": tmp_sub_name = "_".join(bar_attr.name.split()).upper() else: if '-' in bar_attr.name: tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt) else: tmp_sub_name = "_".join(bar_attr.name.split()).upper() + "_" + str(i_cnt) board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic[bdf].name_w_i_cnt = tmp_sub_name
def get_sub_pci_name(i_cnt, bar_attr): tmp_sub_name = '' # if there is only one host bridge, then will discard the index of suffix if i_cnt == 0 and bar_attr.name.upper() == "HOST BRIDGE": tmp_sub_name = "_".join(bar_attr.name.split()).upper() else: if '-' in bar_attr.name: tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt) else: tmp_sub_name = "_".join(bar_attr.name.split()).upper() + "_" + str(i_cnt) return tmp_sub_name
def user_vm_launch(names, args, virt_io, vmid, config): user_vm_type = names['user_vm_types'][vmid] launch_uos = common.undline_name(user_vm_type).lower() board_name = names['board_name'] if 'nuc' in board_name: board_name = 'nuc' if user_vm_type == "CLEARLINUX" and board_name in ("apl-mrb", "nuc"): print('if [ "$1" = "-C" ];then', file=config) print(' if [ $(hostname) = "runc" ]; then', file=config) print(' echo "Already in container exit!"', file=config) print(" exit", file=config) print(" fi", file=config) print(' echo "runc_container"', file=config) print(" run_container", file=config) if board_name == "apl-mrb": print(" exit", file=config) print("fi", file=config) if is_mount_needed(virt_io, vmid): print("", file=config) print('launch_{} {} "{}" $debug'.format( launch_uos, vmid, vmid), file=config) print("", file=config) i = 0 for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: if not mount_flag: i += 1 continue print("umount /data{}".format(i), file=config) i += 1 else: print("else", file=config) print(' launch_{} {}'.format(launch_uos, vmid), file=config) print("fi", file=config) return elif not is_mount_needed(virt_io, vmid): print('launch_{} {}'.format(launch_uos, vmid), file=config) else: print("", file=config) print('launch_{} {} "{}" $debug'.format(launch_uos, vmid, vmid), file=config) print("", file=config) i = 0 for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: if not mount_flag: i += 1 continue print("umount /data{}".format(i), file=config) i += 1
def tap_uos_net(names, virt_io, vmid, config): uos_type = names['uos_types'][vmid] board_name = names['board_name'] vm_name = common.undline_name(uos_type).lower() if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"): i = 0 for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: if not mount_flag: i += 1 continue blk = virt_io['block'][vmid][i] rootfs_img = blk.split(':')[1].strip(':') print('if [ ! -f "/data{}/{}" ]; then'.format(i, rootfs_img), file=config) print(' echo "no /data{}/{}, exit"'.format(i, rootfs_img), file=config) print(" exit", file=config) print("fi", file=config) print("", file=config) i += 1 print("#vm-name used to generate uos-mac address", file=config) print("mac=$(cat /sys/class/net/e*/address)", file=config) print("vm_name=post_vm_id$1", file=config) print("mac_seed=${mac:9:8}-${vm_name}", file=config) print("", file=config) if uos_type in ("VXWORKS", "ZEPHYR", "WINDOWS", "PREEMPT-RT LINUX"): print("vm_name=post_vm_id$1", file=config) for net in virt_io['network'][vmid]: if net: net_name = net if ',' in net: net_name = net.split(',')[0] print("tap_net tap_{}".format(net_name), file=config) print("#check if the vm is running or not", file=config) print("vm_ps=$(pgrep -a -f acrn-dm)", file=config) print('result=$(echo $vm_ps | grep -w "${vm_name}")', file=config) print('if [[ "$result" != "" ]]; then', file=config) print(' echo "$vm_name is running, can\'t create twice!"', file=config) print(" exit", file=config) print("fi", file=config) print("", file=config)
def write_vbar(i_cnt, bdf, pci_bar_dic, bar_attr, config): """ Parser and generate vbar :param i_cnt: the number of pci devices have the same PCI sub class name :param bdf: it is a string what contains BDF :param pci_bar_dic: it is a dictionary of pci vbar for those BDF :param bar_attr: it is a class, contains PIC bar attribute :param config: it is a file pointer of pci information for writing to """ tail = 0 align = ' ' * 48 ptdev_mmio_str = '' tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt) if bdf in pci_bar_dic.keys(): bar_list = list(pci_bar_dic[bdf].keys()) bar_len = len(bar_list) bar_num = 0 for bar_i in bar_list: if not bar_attr.remappable: return if tail == 0: print(", \\", file=config) tail += 1 bar_num += 1 bar_val = pci_bar_dic[bdf][bar_i].addr if pci_bar_dic[bdf][bar_i].remapped: ptdev_mmio_str = 'PTDEV_HI_MMIO_START + ' if bar_num == bar_len: print("{}.vbar_base[{}] = {}{}UL".format( align, bar_i, ptdev_mmio_str, bar_val), file=config) else: print("{}.vbar_base[{}] = {}{}UL, \\".format( align, bar_i, ptdev_mmio_str, bar_val), file=config) else: print("", file=config)