acrn-hypervisor/misc/config_tools/static_allocators/hv_ram.py
Chenli Wei 6d56816e79 misc: modify the logic of generate HV_RAM_START
The current code assume that there must be an HV_RAM_START element in
the scenario and we will generate it if user have not set, the default
value of HV_RAM_START is 0x00400000 which cause an overlap issue.

This patch remove the requires of HV_RAM_START element, calculate
HV_RAM_SIZE and find a region of e820 to run the ACRN which start
address will be HV_RAM_START.

It is still valid if the user set HV_RAM_START by XMLs.

Tracked-On: #6690
Signed-off-by: Chenli Wei <chenli.wei@intel.com>
2022-06-07 18:19:39 +08:00

51 lines
1.9 KiB
Python

#!/usr/bin/env python3
#
# Copyright (C) 2022 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys, os
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
import common, board_cfg_lib, scenario_cfg_lib
HV_RAM_SIZE_MAX = 0x40000000
MEM_ALIGN = 2 * common.SIZE_M
def fn(board_etree, scenario_etree, allocation_etree):
# this dictonary mapped with 'address start':'mem range'
ram_range = {}
vm_num = 0
vm_list = scenario_etree.xpath("//vm")
if vm_list is not None:
vm_num = len(vm_list)
hv_ram_size = common.HV_BASE_RAM_SIZE + common.VM_RAM_SIZE * vm_num
ivshmem_list = scenario_etree.xpath("//IVSHMEM_SIZE/text()")
total_shm_size = 0
for ram_size in ivshmem_list:
try:
total_shm_size += int(ram_size) * 0x100000
except Exception as e:
print(e)
hv_ram_size += 2 * max(total_shm_size, 0x200000)
assert(hv_ram_size <= HV_RAM_SIZE_MAX)
# reseve 16M memory for hv sbuf, ramoops, etc.
reserved_ram = 0x1000000
# We recommend to put hv ram start address high than 0x2000000 to
# reduce memory conflict with GRUB/SOS Kernel.
hv_start_offset = 0x2000000
total_size = reserved_ram + hv_ram_size
for start_addr in list(board_cfg_lib.USED_RAM_RANGE):
if hv_start_offset <= start_addr < 0x80000000:
del board_cfg_lib.USED_RAM_RANGE[start_addr]
ram_range = board_cfg_lib.get_ram_range()
avl_start_addr = board_cfg_lib.find_avl_memory(ram_range, str(total_size), hv_start_offset)
hv_start_addr = int(avl_start_addr, 16) + int(hex(reserved_ram), 16)
hv_start_addr = common.round_up(hv_start_addr, MEM_ALIGN)
board_cfg_lib.USED_RAM_RANGE[hv_start_addr] = total_size
common.append_node("/acrn-config/hv/MEMORY/HV_RAM_START", hex(hv_start_addr), allocation_etree)
common.append_node("/acrn-config/hv/MEMORY/HV_RAM_SIZE", hex(hv_ram_size), allocation_etree)