acrn-config: add OTN1 device config in offline ACPI table

add TSN device OTN1 config into offline ACPI table for TSN device
passthrough to pre-launched RTVM.

v2) update TSN device list from bdf list to vid:pid list.

Tracked-On: #5266

Signed-off-by: Shuang Zheng <shuang.zheng@intel.com>
Acked-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Shuang Zheng 2020-09-10 09:16:31 +08:00 committed by wenlingz
parent c798145478
commit b7e4c69374
4 changed files with 114 additions and 16 deletions

View File

@ -22,10 +22,10 @@ ACPI_BASE = 0x7ff00000
ACPI_RSDP_ADDR_OFFSET = 0x0 # (36 bytes fixed)
ACPI_XSDT_ADDR_OFFSET = 0x80 # (36 bytes + 8*7 table addrs)
ACPI_FADT_ADDR_OFFSET = 0x100 # (244 bytes)
ACPI_MCFG_ADDR_OFFSET = 0x300 # (60 bytes)
ACPI_MADT_ADDR_OFFSET = 0x340 # (depends on #CPUs)
ACPI_TPM2_ADDR_OFFSET = 0x1000 # (52 bytes)
ACPI_DSDT_ADDR_OFFSET = 0x200 # (variable - can go up to 0x100000)
ACPI_DSDT_ADDR_OFFSET = 0x200 # (variable)
ACPI_MCFG_ADDR_OFFSET = 0x400 # (60 bytes)
ACPI_MADT_ADDR_OFFSET = 0x440 # (depends on #CPUs)
ACPI_TPM2_ADDR_OFFSET = 0x1100 # (52 bytes)
ACPI_RSDP_ADDR = (ACPI_BASE + ACPI_RSDP_ADDR_OFFSET)
ACPI_XSDT_ADDR = (ACPI_BASE + ACPI_XSDT_ADDR_OFFSET)
@ -47,3 +47,7 @@ VIOAPIC_BASE = 0xFEC00000
ACPI_MADT_TYPE_LOCAL_APIC = 0
ACPI_MADT_TYPE_LOCAL_APIC_NMI = 4
TSN_DEVICE_LIST = ['8086:4ba0',
'8086:4bb0',
'8086:4b32']

View File

@ -8,6 +8,7 @@
import os, re, argparse, shutil
import xml.etree.ElementTree as ElementTree
from acpi_const import *
import board_cfg_lib
def calculate_checksum8():
'''
@ -31,7 +32,6 @@ def gen_rsdp(dest_vm_acpi_path):
with open(os.path.join(TEMPLATE_ACPI_PATH, rsdp_asl), 'r') as src:
for line in src.readlines():
if re.search(p_xsdt_addr, line):
print('ACPI_XSDT_ADDR: ', ACPI_XSDT_ADDR)
lines.append(re.sub(p_xsdt_addr, 'XSDT Address : {0:016X}'.format(ACPI_XSDT_ADDR), line))
else:
lines.append(line)
@ -349,7 +349,7 @@ def gen_tpm2(dest_vm_acpi_path, passthru_devices):
dest.writelines(lines)
def gen_dsdt(dest_vm_acpi_path, passthru_devices):
def gen_dsdt(dest_vm_acpi_path, passthru_devices, board_info):
'''
generate dsdt.asl
:param dest_vm_acpi_path: the path to store generated ACPI asl code
@ -358,6 +358,7 @@ def gen_dsdt(dest_vm_acpi_path, passthru_devices):
'''
dsdt_asl = 'dsdt.asl'
p_dsdt_start = r'{'
(bdf_desc_map, bdf_vpid_map) = board_cfg_lib.get_pci_info(board_info)
with open(os.path.join(dest_vm_acpi_path, dsdt_asl), 'w') as dest:
lines = []
with open(os.path.join(TEMPLATE_ACPI_PATH, dsdt_asl), 'r') as src:
@ -365,10 +366,16 @@ def gen_dsdt(dest_vm_acpi_path, passthru_devices):
lines.append(line)
if line.startswith(p_dsdt_start):
for passthru_device in passthru_devices:
passthru_bdf = None
passthru_vpid = None
for bdf in bdf_desc_map.keys():
if bdf_desc_map[bdf].find(passthru_device) >= 0:
passthru_bdf = bdf
break
if passthru_bdf is not None and passthru_bdf in bdf_vpid_map.keys():
passthru_vpid = bdf_vpid_map[passthru_bdf]
if passthru_device in ['TPM2']:
tpm2_asl = os.path.join(dest_vm_acpi_path, 'dsdt_tpm2.asl')
if not os.path.isfile(tpm2_asl):
tpm2_asl = os.path.join(TEMPLATE_ACPI_PATH, 'dsdt_tpm2.asl')
tpm2_asl = os.path.join(TEMPLATE_ACPI_PATH, 'dsdt_tpm2.asl')
start = False
with open(tpm2_asl, 'r') as tpm2_src:
for tpm2_line in tpm2_src.readlines():
@ -380,6 +387,19 @@ def gen_dsdt(dest_vm_acpi_path, passthru_devices):
continue
if start:
lines.append(tpm2_line)
elif passthru_vpid is not None and passthru_vpid == TSN_DEVICE_LIST[1]:
otn1_asl = os.path.join(TEMPLATE_ACPI_PATH, 'dsdt_tsn_otn1.asl')
start = False
with open(otn1_asl, 'r') as otn1_src:
for otn1_line in otn1_src.readlines():
if otn1_line.startswith('{'):
start = True
continue
if otn1_line.startswith('}'):
start = False
continue
if start:
lines.append(otn1_line)
else:
pass
dest.writelines(lines)
@ -452,7 +472,7 @@ def main(args):
err_dic['vm,cpu_affinity,pcpu_id'] = emsg
gen_madt(dest_vm_acpi_path, vcpu_len)
gen_tpm2(dest_vm_acpi_path, passthru_devices)
gen_dsdt(dest_vm_acpi_path, passthru_devices)
gen_dsdt(dest_vm_acpi_path, passthru_devices, board)
print('generate ASL code of ACPI tables for VM {} into {}'.format(vm_id, dest_vm_acpi_path))
return err_dic

View File

@ -132,9 +132,19 @@ def check_iasl():
:return: True if iasl installed.
'''
try:
output = subprocess.check_output(['iasl', '-h']).decode('utf8')
if 'Usage: iasl [Options] [Files]' in output:
return True
p_version = 'ASL+ Optimizing Compiler/Disassembler version'
min_version = 20190703
output = subprocess.check_output(['iasl', '-v']).decode('utf8')
if p_version in output:
try:
for line in output.split('\n'):
if line.find(p_version) >= 0:
version = int(line.split(p_version)[1].strip())
if version >= min_version:
return True
except:
pass
return False
elif 'command not found' in output:
return False
else:
@ -154,7 +164,7 @@ def main(args):
else:
DEST_ACPI_PATH = os.path.join(common.SOURCE_ROOT_DIR, args.asl, 'scenarios', scenario_name, board_type)
if args.out is None:
DEST_ACPI_BIN_PATH = os.path.join(os.getcwd(), 'build', 'acpi')
DEST_ACPI_BIN_PATH = os.path.join(common.SOURCE_ROOT_DIR, 'build', 'hypervisor', 'acpi')
else:
DEST_ACPI_BIN_PATH = args.out
@ -162,7 +172,7 @@ def main(args):
shutil.rmtree(DEST_ACPI_BIN_PATH)
if not check_iasl():
print("Please install iasl tool from https://www.acpica.org/downloads before ACPI generation.")
print("Please install iasl tool with version >= 20190703 from https://www.acpica.org/downloads before ACPI generation.")
return 1
for config in os.listdir(DEST_ACPI_PATH):
@ -186,7 +196,7 @@ if __name__ == '__main__':
parser.add_argument("--asl", default=None, help="the input folder to store the ACPI ASL code. "
"If not specified, the path for the ASL code is"
"misc/vm_configs/scenarios/[scenario]/[board]/")
parser.add_argument("--out", default="build/hypervisor/", help="the output folder to store the ACPI binary code. "
parser.add_argument("--out", default=None, help="the output folder to store the ACPI binary code. "
"If not specified, the path for the binary code is"
"build/acpi/")

View File

@ -0,0 +1,64 @@
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20180105 (64-bit version)
* Copyright (c) 2000 - 2018 Intel Corporation
*
* Original Table Header:
* Signature "DSDT"
* Length 0x00000102 (258)
* Revision 0x03
* Checksum 0x08
* OEM ID "ACRN "
* OEM Table ID "ACRNDSDT"
* OEM Revision 0x00000001 (1)
* Compiler ID "INTL"
* Compiler Version 0x20180105 (538444037)
*/
DefinitionBlock ("", "DSDT", 3, "ACRN ", "ACRNDSDT", 0x00000001)
{
Scope (_SB)
{
Device (OTN1)
{
Name (_ADR, 0x00020000) // _ADR: Address
OperationRegion (TSRT, PCI_Config, Zero, 0x0100)
Field (TSRT, AnyAcc, NoLock, Preserve)
{
DVID, 16,
Offset (0x10),
TADL, 32,
TADH, 32
}
}
Device (PCS2)
{
Name (_HID, "INTC1033") // _HID: Hardware ID
Name (_UID, Zero) // _UID: Unique ID
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
Method (_CRS, 0, Serialized) // _CRS: Current Resource Settings
{
Name (PCSR, ResourceTemplate ()
{
Memory32Fixed (ReadWrite,
0x00000000, // Address Base
0x00000004, // Address Length
_Y00)
Memory32Fixed (ReadWrite,
0x00000000, // Address Base
0x00000004, // Address Length
_Y01)
})
CreateDWordField (PCSR, \_SB.PCS2._CRS._Y00._BAS, MAL0) // _BAS: Base Address
MAL0 = ((^^OTN1.TADL & 0xFFFFF000) + 0x0200)
CreateDWordField (PCSR, \_SB.PCS2._CRS._Y01._BAS, MDL0) // _BAS: Base Address
MDL0 = ((^^OTN1.TADL & 0xFFFFF000) + 0x0204)
Return (PCSR) /* \_SB_.PCS2._CRS.PCSR */
}
}
}
}