mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-05 11:36:50 +00:00
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:
parent
5629ade9a0
commit
773889bb65
@ -156,6 +156,7 @@ C_SRCS += scenarios/$(SCENARIO_NAME)/pt_dev.c
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
C_SRCS += boot/acpi.c
|
C_SRCS += boot/acpi.c
|
||||||
|
C_SRCS += boot/dmar_info.c
|
||||||
C_SRCS += boot/dmar_parse.c
|
C_SRCS += boot/dmar_parse.c
|
||||||
C_SRCS += boot/cmdline.c
|
C_SRCS += boot/cmdline.c
|
||||||
C_SRCS += boot/guest/vboot_wrapper.c
|
C_SRCS += boot/guest/vboot_wrapper.c
|
||||||
@ -243,8 +244,6 @@ C_SRCS += dm/vpci/pci_pt.c
|
|||||||
C_SRCS += dm/vpci/vmsi.c
|
C_SRCS += dm/vpci/vmsi.c
|
||||||
C_SRCS += dm/vpci/vmsix.c
|
C_SRCS += dm/vpci/vmsix.c
|
||||||
|
|
||||||
C_SRCS += bsp/const_dmar.c
|
|
||||||
|
|
||||||
# retpoline support
|
# retpoline support
|
||||||
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 7 ] && [ $(GCC_MINOR) -ge 3 ] && echo true))
|
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 7 ] && [ $(GCC_MINOR) -ge 3 ] && echo true))
|
||||||
CFLAGS += -mindirect-branch=thunk-extern -mindirect-branch-register
|
CFLAGS += -mindirect-branch=thunk-extern -mindirect-branch-register
|
||||||
|
@ -7,11 +7,6 @@
|
|||||||
#include <vtd.h>
|
#include <vtd.h>
|
||||||
#include <platform_acpi_info.h>
|
#include <platform_acpi_info.h>
|
||||||
|
|
||||||
#ifndef CONFIG_DMAR_PARSE_ENABLED
|
|
||||||
|
|
||||||
#define MAX_DRHDS 4
|
|
||||||
#define MAX_DRHD_DEVSCOPES 4
|
|
||||||
|
|
||||||
static struct dmar_dev_scope drhd0_dev_scope[MAX_DRHD_DEVSCOPES] = {
|
static struct dmar_dev_scope drhd0_dev_scope[MAX_DRHD_DEVSCOPES] = {
|
||||||
{
|
{
|
||||||
.bus = DRHD0_DEVSCOPE0_BUS,
|
.bus = DRHD0_DEVSCOPE0_BUS,
|
||||||
@ -125,7 +120,7 @@ static struct dmar_drhd drhd_info_array[MAX_DRHDS] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct dmar_info sbl_dmar_info = {
|
static struct dmar_info plat_dmar_info = {
|
||||||
.drhd_count = DRHD_COUNT,
|
.drhd_count = DRHD_COUNT,
|
||||||
.drhd_units = drhd_info_array,
|
.drhd_units = drhd_info_array,
|
||||||
};
|
};
|
||||||
@ -136,6 +131,8 @@ static struct dmar_info sbl_dmar_info = {
|
|||||||
*/
|
*/
|
||||||
struct dmar_info *get_dmar_info(void)
|
struct dmar_info *get_dmar_info(void)
|
||||||
{
|
{
|
||||||
return &sbl_dmar_info;
|
#ifdef CONFIG_DMAR_PARSE_ENABLED
|
||||||
}
|
parse_dmar_table(&plat_dmar_info);
|
||||||
#endif
|
#endif
|
||||||
|
return &plat_dmar_info;
|
||||||
|
}
|
@ -68,7 +68,6 @@ struct acpi_dmar_device_scope {
|
|||||||
|
|
||||||
typedef int32_t (*dmar_iter_t)(struct acpi_dmar_header*, void*);
|
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 int32_t dmar_unit_cnt;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -236,15 +235,9 @@ handle_one_drhd(struct acpi_dmar_hardware_unit *acpi_drhd,
|
|||||||
drhd->reg_base_addr = acpi_drhd->address;
|
drhd->reg_base_addr = acpi_drhd->address;
|
||||||
|
|
||||||
dev_count = get_drhd_dev_scope_cnt(acpi_drhd);
|
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;
|
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 -
|
remaining = acpi_drhd->header.length -
|
||||||
sizeof(struct acpi_dmar_hardware_unit);
|
sizeof(struct acpi_dmar_hardware_unit);
|
||||||
@ -281,20 +274,16 @@ handle_one_drhd(struct acpi_dmar_hardware_unit *acpi_drhd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parse_dmar_table(void)
|
int32_t parse_dmar_table(struct dmar_info *plat_dmar_info)
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
struct acpi_dmar_hardware_unit *acpi_drhd;
|
struct acpi_dmar_hardware_unit *acpi_drhd;
|
||||||
|
|
||||||
/* find out how many dmar units */
|
/* find out how many dmar units */
|
||||||
dmar_iterate_tbl(drhd_count_iter, NULL);
|
dmar_iterate_tbl(drhd_count_iter, NULL);
|
||||||
|
ASSERT(dmar_unit_cnt <= MAX_DRHDS, "parsed dmar_unit_cnt > MAX_DRHDS");
|
||||||
|
|
||||||
/* alloc memory for dmar uint */
|
plat_dmar_info->drhd_count = dmar_unit_cnt;
|
||||||
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;
|
|
||||||
|
|
||||||
for (i = 0; i < dmar_unit_cnt; i++) {
|
for (i = 0; i < dmar_unit_cnt; i++) {
|
||||||
acpi_drhd = drhd_find_by_index(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)
|
if (acpi_drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK)
|
||||||
ASSERT((i+1) == dmar_unit_cnt,
|
ASSERT((i+1) == dmar_unit_cnt,
|
||||||
"drhd with flags set should be the last one");
|
"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;
|
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
|
#endif
|
||||||
|
@ -457,6 +457,9 @@ static inline uint16_t dma_frcd_up_sid(uint64_t up_sid)
|
|||||||
return ((uint16_t)up_sid & 0xffffU);
|
return ((uint16_t)up_sid & 0xffffU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_DRHDS 4
|
||||||
|
#define MAX_DRHD_DEVSCOPES 4
|
||||||
|
|
||||||
#define DMAR_CONTEXT_TRANSLATION_TYPE_TRANSLATED 0x00U
|
#define DMAR_CONTEXT_TRANSLATION_TYPE_TRANSLATED 0x00U
|
||||||
#define DMAR_CONTEXT_TRANSLATION_TYPE_RESERVED 0x01U
|
#define DMAR_CONTEXT_TRANSLATION_TYPE_RESERVED 0x01U
|
||||||
#define DMAR_CONTEXT_TRANSLATION_TYPE_PASSED_THROUGH 0x02U
|
#define DMAR_CONTEXT_TRANSLATION_TYPE_PASSED_THROUGH 0x02U
|
||||||
@ -516,6 +519,10 @@ union dmar_ir_entry {
|
|||||||
|
|
||||||
extern struct dmar_info *get_dmar_info(void);
|
extern struct dmar_info *get_dmar_info(void);
|
||||||
|
|
||||||
|
#ifdef CONFIG_DMAR_PARSE_ENABLED
|
||||||
|
int32_t parse_dmar_table(struct dmar_info *plat_dmar_info);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file vtd.h
|
* @file vtd.h
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user