acrn-config: integrate PTCT table for pre-launched RTVM

fill physical PTCT table into pre-launched vACPI table when PSRAM
is configured to passthrough to pre-launched RTVM.

Tracked-On: #5418

Signed-off-by: Shuang Zheng <shuang.zheng@intel.com>
This commit is contained in:
Shuang Zheng 2020-10-20 22:10:05 +08:00 committed by wenlingz
parent faeef67c20
commit 0e9775f4a4
5 changed files with 37 additions and 1 deletions

View File

@ -15,7 +15,7 @@ TEMPLATE_ACPI_PATH = os.path.join(VM_CONFIGS_PATH, 'acpi', 'template')
ACPI_TABLE_LIST = [('rsdp.asl', 'rsdp.aml'), ('xsdt.asl', 'xsdt.aml'), ('facp.asl', 'facp.aml'),
('mcfg.asl', 'mcfg.aml'), ('apic.asl', 'apic.aml'), ('tpm2.asl', 'tpm2.aml'),
('dsdt.asl', 'dsdt.aml')]
('dsdt.asl', 'dsdt.aml'), ('PTCT', 'ptct.aml')]
ACPI_BASE = 0x7ff00000
@ -25,6 +25,7 @@ ACPI_FADT_ADDR_OFFSET = 0x100 # (244 bytes)
ACPI_DSDT_ADDR_OFFSET = 0x200 # (variable)
ACPI_MCFG_ADDR_OFFSET = 0x400 # (60 bytes)
ACPI_MADT_ADDR_OFFSET = 0x440 # (depends on #CPUs)
ACPI_PTCT_ADDR_OFFSET = 0xF00
ACPI_TPM2_ADDR_OFFSET = 0x1100 # (52 bytes)
ACPI_RSDP_ADDR = (ACPI_BASE + ACPI_RSDP_ADDR_OFFSET)
@ -34,6 +35,7 @@ ACPI_MCFG_ADDR = (ACPI_BASE + ACPI_MCFG_ADDR_OFFSET)
ACPI_MADT_ADDR = (ACPI_BASE + ACPI_MADT_ADDR_OFFSET)
ACPI_TPM2_ADDR = (ACPI_BASE + ACPI_TPM2_ADDR_OFFSET)
ACPI_DSDT_ADDR = (ACPI_BASE + ACPI_DSDT_ADDR_OFFSET)
ACPI_PTCT_ADDR = (ACPI_BASE + ACPI_PTCT_ADDR_OFFSET)
ACPI_FACS_ADDR = 0x0
PM1A_EVN_LEN = 0x4
@ -51,3 +53,5 @@ ACPI_MADT_TYPE_LOCAL_APIC_NMI = 4
TSN_DEVICE_LIST = ['8086:4ba0',
'8086:4bb0',
'8086:4b32']
PTCT = 'PTCT'

View File

@ -50,6 +50,7 @@ def gen_xsdt(dest_vm_acpi_path, passthru_devices):
p_mcfg_addr = r'ACPI Table Address 1 : ([0-9a-fA-F]{16})'
p_madt_addr = r'ACPI Table Address 2 : ([0-9a-fA-F]{16})'
p_tpm2_addr = r'ACPI Table Address 3 : ([0-9a-fA-F]{16})'
p_ptct_addr = r'ACPI Table Address 4 : ([0-9a-fA-F]{16})'
with open(os.path.join(dest_vm_acpi_path, xsdt_asl), 'w') as dest:
lines = []
@ -64,6 +65,9 @@ def gen_xsdt(dest_vm_acpi_path, passthru_devices):
elif re.search(p_tpm2_addr, line):
if 'TPM2' in passthru_devices:
lines.append(re.sub(p_tpm2_addr, 'ACPI Table Address 3 : {0:016X}'.format(ACPI_TPM2_ADDR), line))
elif re.search(p_ptct_addr, line):
if 'PTCT' in passthru_devices:
lines.append(re.sub(p_ptct_addr, 'ACPI Table Address 4 : {0:016X}'.format(ACPI_PTCT_ADDR), line))
else:
lines.append(line)
@ -454,11 +458,29 @@ def main(args):
if pcpu_id is not None and pcpu_id.text.strip() in pcpu_list:
dict_vcpu_list[vm_id].append(pcpu_id)
PASSTHROUGH_PTCT = False
PRELAUNCHED_RTVM_ID = None
try:
if scenario_root.find('hv/FEATURES/PSRAM/PSRAM_ENABLED').text.strip() == 'y' \
and scenario_root.find('hv/FEATURES/PSRAM/PSRAM_PASSTHROUGH_PRE_RTVM').text.strip() == 'y':
PASSTHROUGH_PTCT = True
for vm in scenario_root.findall('vm'):
vm_id = vm.attrib['id']
vm_type_node = vm.find('vm_type')
if (vm_type_node is not None) and (vm_type_node.text in ['PRE_RT_VM']):
PRELAUNCHED_RTVM_ID = vm_id
break
except:
PASSTHROUGH_PTCT = False
for vm_id, passthru_devices in dict_passthru_devices.items():
print('start to generate ACPI ASL code for VM{}'.format(vm_id))
dest_vm_acpi_path = os.path.join(DEST_ACPI_PATH, 'VM'+vm_id)
if not os.path.isdir(dest_vm_acpi_path):
os.makedirs(dest_vm_acpi_path)
if PASSTHROUGH_PTCT is True and vm_id == PRELAUNCHED_RTVM_ID:
passthru_devices.append(PTCT)
shutil.copy(os.path.join(VM_CONFIGS_PATH, 'acpi', board_type, PTCT), dest_vm_acpi_path)
gen_rsdp(dest_vm_acpi_path)
gen_xsdt(dest_vm_acpi_path, passthru_devices)
gen_fadt(dest_vm_acpi_path, board_root)

View File

@ -33,6 +33,10 @@ def asl_to_aml(dest_vm_acpi_path, dest_vm_acpi_bin_path):
os.remove(os.path.join(dest_vm_acpi_path, acpi_table[1]))
rmsg = 'failed to compile {}'.format(acpi_table[0])
break
elif acpi_table[0] == PTCT:
if PTCT in os.listdir(dest_vm_acpi_path):
shutil.copyfile(os.path.join(dest_vm_acpi_path, acpi_table[0]),
os.path.join(dest_vm_acpi_bin_path, acpi_table[1]))
else:
rc = exec_command('iasl {}'.format(acpi_table[0]))
if rc == 0 and os.path.isfile(os.path.join(dest_vm_acpi_path, acpi_table[1])):
@ -92,6 +96,11 @@ def aml_to_bin(dest_vm_acpi_path, dest_vm_acpi_bin_path, acpi_bin_name):
with open(os.path.join(dest_vm_acpi_bin_path, ACPI_TABLE_LIST[6][1]), 'rb') as asl:
acpi_bin.write(asl.read())
if PTCT in os.listdir(dest_vm_acpi_path):
acpi_bin.seek(ACPI_PTCT_ADDR_OFFSET)
with open(os.path.join(dest_vm_acpi_bin_path, ACPI_TABLE_LIST[7][1]), 'rb') as asl:
acpi_bin.write(asl.read())
acpi_bin.seek(0xfffff)
acpi_bin.write(b'\0')
shutil.move(acpi_bin_file, os.path.join(dest_vm_acpi_bin_path, '..', acpi_bin_name))

View File

@ -22,3 +22,4 @@
[0008] ACPI Table Address 1 : 00000000000F2640
[0008] ACPI Table Address 2 : 00000000000F2680
[0008] ACPI Table Address 3 : 00000000000F2800
[0008] ACPI Table Address 4 : 00000000000F3300

Binary file not shown.