hv: dmar_parse: remove dynamic memory allocation

This patch removes the dynamic memory allocation in dmar_parse.c.

v1 -> v2:
 - rename 'const_dmar.c' to 'dmar_info.c' and move it to
   'boot' directory
 - add CONFIG_DMAR_PARSE_ENABLED check for function declaration

Tracked-On: #861
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
This commit is contained in:
Shiqing Gao
2019-05-09 13:11:10 +08:00
committed by ACRN System Integration
parent 5629ade9a0
commit 773889bb65
4 changed files with 19 additions and 38 deletions

138
hypervisor/boot/dmar_info.c Normal file
View File

@@ -0,0 +1,138 @@
/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <vtd.h>
#include <platform_acpi_info.h>
static struct dmar_dev_scope drhd0_dev_scope[MAX_DRHD_DEVSCOPES] = {
{
.bus = DRHD0_DEVSCOPE0_BUS,
.devfun = DRHD0_DEVSCOPE0_PATH
},
{
.bus = DRHD0_DEVSCOPE1_BUS,
.devfun = DRHD0_DEVSCOPE1_PATH
},
{
.bus = DRHD0_DEVSCOPE2_BUS,
.devfun = DRHD0_DEVSCOPE2_PATH
},
{
.bus = DRHD0_DEVSCOPE3_BUS,
.devfun = DRHD0_DEVSCOPE3_PATH
}
};
static struct dmar_dev_scope drhd1_dev_scope[MAX_DRHD_DEVSCOPES] = {
{
.type = ACPI_DMAR_SCOPE_TYPE_IOAPIC,
.id = DRHD1_IOAPIC_ID,
.bus = DRHD1_DEVSCOPE0_BUS,
.devfun = DRHD1_DEVSCOPE0_PATH
},
{
.bus = DRHD1_DEVSCOPE1_BUS,
.devfun = DRHD1_DEVSCOPE1_PATH
},
{
.bus = DRHD1_DEVSCOPE2_BUS,
.devfun = DRHD1_DEVSCOPE2_PATH
},
{
.bus = DRHD1_DEVSCOPE3_BUS,
.devfun = DRHD1_DEVSCOPE3_PATH
}
};
static struct dmar_dev_scope drhd2_dev_scope[MAX_DRHD_DEVSCOPES] = {
{
.bus = DRHD2_DEVSCOPE0_BUS,
.devfun = DRHD2_DEVSCOPE0_PATH
},
{
.bus = DRHD2_DEVSCOPE1_BUS,
.devfun = DRHD2_DEVSCOPE1_PATH
},
{
.bus = DRHD2_DEVSCOPE2_BUS,
.devfun = DRHD2_DEVSCOPE2_PATH
},
{
.bus = DRHD2_DEVSCOPE3_BUS,
.devfun = DRHD2_DEVSCOPE3_PATH
}
};
static struct dmar_dev_scope drhd3_dev_scope[MAX_DRHD_DEVSCOPES] = {
{
.bus = DRHD3_DEVSCOPE0_BUS,
.devfun = DRHD3_DEVSCOPE0_PATH
},
{
.bus = DRHD3_DEVSCOPE1_BUS,
.devfun = DRHD3_DEVSCOPE1_PATH
},
{
.bus = DRHD3_DEVSCOPE2_BUS,
.devfun = DRHD3_DEVSCOPE2_PATH
},
{
.bus = DRHD3_DEVSCOPE3_BUS,
.devfun = DRHD3_DEVSCOPE3_PATH
}
};
static struct dmar_drhd drhd_info_array[MAX_DRHDS] = {
{
.dev_cnt = DRHD0_DEV_CNT,
.segment = DRHD0_SEGMENT,
.flags = DRHD0_FLAGS,
.reg_base_addr = DRHD0_REG_BASE,
.ignore = DRHD0_IGNORE,
.devices = drhd0_dev_scope
},
{
.dev_cnt = DRHD1_DEV_CNT,
.segment = DRHD1_SEGMENT,
.flags = DRHD1_FLAGS,
.reg_base_addr = DRHD1_REG_BASE,
.ignore = DRHD1_IGNORE,
.devices = drhd1_dev_scope
},
{
.dev_cnt = DRHD2_DEV_CNT,
.segment = DRHD2_SEGMENT,
.flags = DRHD2_FLAGS,
.reg_base_addr = DRHD2_REG_BASE,
.ignore = DRHD2_IGNORE,
.devices = drhd2_dev_scope
},
{
.dev_cnt = DRHD3_DEV_CNT,
.segment = DRHD3_SEGMENT,
.flags = DRHD3_FLAGS,
.reg_base_addr = DRHD3_REG_BASE,
.ignore = DRHD3_IGNORE,
.devices = drhd3_dev_scope
}
};
static struct dmar_info plat_dmar_info = {
.drhd_count = DRHD_COUNT,
.drhd_units = drhd_info_array,
};
/**
* @post return != NULL
* @post return->drhd_count > 0U
*/
struct dmar_info *get_dmar_info(void)
{
#ifdef CONFIG_DMAR_PARSE_ENABLED
parse_dmar_table(&plat_dmar_info);
#endif
return &plat_dmar_info;
}

View File

@@ -68,7 +68,6 @@ struct acpi_dmar_device_scope {
typedef int32_t (*dmar_iter_t)(struct acpi_dmar_header*, void*);
static struct dmar_info dmar_info_parsed;
static int32_t dmar_unit_cnt;
static void
@@ -236,15 +235,9 @@ handle_one_drhd(struct acpi_dmar_hardware_unit *acpi_drhd,
drhd->reg_base_addr = acpi_drhd->address;
dev_count = get_drhd_dev_scope_cnt(acpi_drhd);
ASSERT(dev_count <= MAX_DRHD_DEVSCOPES, "parsed dev_count > MAX_DRHD_DEVSCOPES");
drhd->dev_cnt = dev_count;
if (dev_count) {
drhd->devices =
calloc(dev_count, sizeof(struct dmar_dev_scope));
ASSERT(drhd->devices, "");
} else {
drhd->devices = NULL;
return 0;
}
remaining = acpi_drhd->header.length -
sizeof(struct acpi_dmar_hardware_unit);
@@ -281,20 +274,16 @@ handle_one_drhd(struct acpi_dmar_hardware_unit *acpi_drhd,
return 0;
}
static int32_t parse_dmar_table(void)
int32_t parse_dmar_table(struct dmar_info *plat_dmar_info)
{
int32_t i;
struct acpi_dmar_hardware_unit *acpi_drhd;
/* find out how many dmar units */
dmar_iterate_tbl(drhd_count_iter, NULL);
ASSERT(dmar_unit_cnt <= MAX_DRHDS, "parsed dmar_unit_cnt > MAX_DRHDS");
/* alloc memory for dmar uint */
dmar_info_parsed.drhd_units =
calloc(dmar_unit_cnt, sizeof(struct dmar_drhd));
ASSERT(dmar_info_parsed.drhd_units, "");
dmar_info_parsed.drhd_count = dmar_unit_cnt;
plat_dmar_info->drhd_count = dmar_unit_cnt;
for (i = 0; i < dmar_unit_cnt; i++) {
acpi_drhd = drhd_find_by_index(i);
@@ -303,21 +292,10 @@ static int32_t parse_dmar_table(void)
if (acpi_drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK)
ASSERT((i+1) == dmar_unit_cnt,
"drhd with flags set should be the last one");
handle_one_drhd(acpi_drhd, &dmar_info_parsed.drhd_units[i]);
handle_one_drhd(acpi_drhd, &(plat_dmar_info->drhd_units[i]));
}
return 0;
}
/**
* @post return != NULL
* @post return->drhd_count > 0U
*/
struct dmar_info *get_dmar_info(void)
{
if (dmar_info_parsed.drhd_count == 0) {
parse_dmar_table();
}
return &dmar_info_parsed;
}
#endif