diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 3940930d6..5b310da12 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -225,7 +225,6 @@ ifneq (,$(wildcard scenarios/$(SCENARIO_NAME)/pci_dev.c)) HW_C_SRCS += scenarios/$(SCENARIO_NAME)/pci_dev.c endif HW_C_SRCS += boot/acpi_base.c -HW_C_SRCS += boot/dmar_info.c HW_C_SRCS += boot/cmdline.c # ACPI parsing component # This part should be isolated from FuSa Cert diff --git a/hypervisor/acpi_parser/dmar_parse.c b/hypervisor/acpi_parser/dmar_parse.c index 1534c181c..e3d5203f7 100644 --- a/hypervisor/acpi_parser/dmar_parse.c +++ b/hypervisor/acpi_parser/dmar_parse.c @@ -21,6 +21,8 @@ struct find_iter_args { typedef int32_t (*dmar_iter_t)(struct acpi_dmar_header*, void*); static uint32_t dmar_unit_cnt; +static struct dmar_drhd drhd_info_array[MAX_DRHDS]; +static struct dmar_dev_scope drhd_dev_scope[MAX_DRHDS][MAX_DRHD_DEVSCOPES]; static void *get_dmar_table(void) { @@ -237,6 +239,7 @@ int32_t parse_dmar_table(struct dmar_info *plat_dmar_info) ASSERT(dmar_unit_cnt <= MAX_DRHDS, "parsed dmar_unit_cnt > MAX_DRHDS"); plat_dmar_info->drhd_count = dmar_unit_cnt; + plat_dmar_info->drhd_units = drhd_info_array; for (i = 0U; i < dmar_unit_cnt; i++) { acpi_drhd = drhd_find_by_index(i); @@ -245,6 +248,7 @@ int32_t parse_dmar_table(struct dmar_info *plat_dmar_info) if (acpi_drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK) ASSERT((i + 1U) == dmar_unit_cnt, "drhd with flags set should be the last one"); + plat_dmar_info->drhd_units[i].devices = drhd_dev_scope[i]; handle_one_drhd(acpi_drhd, &(plat_dmar_info->drhd_units[i])); } diff --git a/hypervisor/arch/x86/configs/apl-mrb/board.c b/hypervisor/arch/x86/configs/apl-mrb/board.c index 20e1314d4..4f1fd286f 100644 --- a/hypervisor/arch/x86/configs/apl-mrb/board.c +++ b/hypervisor/arch/x86/configs/apl-mrb/board.c @@ -5,7 +5,14 @@ */ #include +#include +#ifndef CONFIG_ACPI_PARSE_ENABLED +#error "DMAR info is not available, please set ACPI_PARSE_ENABLED to y in Kconfig. \ + Or use acrn-config tool to generate platform DMAR info." +#endif + +struct dmar_info plat_dmar_info; struct platform_clos_info platform_clos_array[0]; uint16_t platform_clos_num = 0; const struct cpu_state_table board_cpu_state_tbl; diff --git a/hypervisor/arch/x86/configs/apl-up2/board.c b/hypervisor/arch/x86/configs/apl-up2/board.c index a7f9dc36c..ccab657fb 100644 --- a/hypervisor/arch/x86/configs/apl-up2/board.c +++ b/hypervisor/arch/x86/configs/apl-up2/board.c @@ -6,6 +6,14 @@ #include #include +#include + +#ifndef CONFIG_ACPI_PARSE_ENABLED +#error "DMAR info is not available, please set ACPI_PARSE_ENABLED to y in Kconfig. \ + Or use acrn-config tool to generate platform DMAR info." +#endif + +struct dmar_info plat_dmar_info; struct platform_clos_info platform_clos_array[4] = { { diff --git a/hypervisor/arch/x86/configs/dnv-cb2/board.c b/hypervisor/arch/x86/configs/dnv-cb2/board.c index 20e1314d4..4f1fd286f 100644 --- a/hypervisor/arch/x86/configs/dnv-cb2/board.c +++ b/hypervisor/arch/x86/configs/dnv-cb2/board.c @@ -5,7 +5,14 @@ */ #include +#include +#ifndef CONFIG_ACPI_PARSE_ENABLED +#error "DMAR info is not available, please set ACPI_PARSE_ENABLED to y in Kconfig. \ + Or use acrn-config tool to generate platform DMAR info." +#endif + +struct dmar_info plat_dmar_info; struct platform_clos_info platform_clos_array[0]; uint16_t platform_clos_num = 0; const struct cpu_state_table board_cpu_state_tbl; diff --git a/hypervisor/arch/x86/configs/generic/board.c b/hypervisor/arch/x86/configs/generic/board.c index 20e1314d4..4f1fd286f 100644 --- a/hypervisor/arch/x86/configs/generic/board.c +++ b/hypervisor/arch/x86/configs/generic/board.c @@ -5,7 +5,14 @@ */ #include +#include +#ifndef CONFIG_ACPI_PARSE_ENABLED +#error "DMAR info is not available, please set ACPI_PARSE_ENABLED to y in Kconfig. \ + Or use acrn-config tool to generate platform DMAR info." +#endif + +struct dmar_info plat_dmar_info; struct platform_clos_info platform_clos_array[0]; uint16_t platform_clos_num = 0; const struct cpu_state_table board_cpu_state_tbl; diff --git a/hypervisor/arch/x86/configs/icl-rvp/board.c b/hypervisor/arch/x86/configs/icl-rvp/board.c index 830a75dcc..e64158516 100644 --- a/hypervisor/arch/x86/configs/icl-rvp/board.c +++ b/hypervisor/arch/x86/configs/icl-rvp/board.c @@ -5,6 +5,13 @@ */ #include +#include +#ifndef CONFIG_ACPI_PARSE_ENABLED +#error "DMAR info is not available, please set ACPI_PARSE_ENABLED to y in Kconfig. \ + Or use acrn-config tool to generate platform DMAR info." +#endif + +struct dmar_info plat_dmar_info; struct platform_clos_info platform_clos_array[0]; uint16_t platform_clos_num = 0; diff --git a/hypervisor/arch/x86/configs/nuc6cayh/board.c b/hypervisor/arch/x86/configs/nuc6cayh/board.c index 20e1314d4..4f1fd286f 100644 --- a/hypervisor/arch/x86/configs/nuc6cayh/board.c +++ b/hypervisor/arch/x86/configs/nuc6cayh/board.c @@ -5,7 +5,14 @@ */ #include +#include +#ifndef CONFIG_ACPI_PARSE_ENABLED +#error "DMAR info is not available, please set ACPI_PARSE_ENABLED to y in Kconfig. \ + Or use acrn-config tool to generate platform DMAR info." +#endif + +struct dmar_info plat_dmar_info; struct platform_clos_info platform_clos_array[0]; uint16_t platform_clos_num = 0; const struct cpu_state_table board_cpu_state_tbl; diff --git a/hypervisor/arch/x86/configs/nuc7i7dnb/board.c b/hypervisor/arch/x86/configs/nuc7i7dnb/board.c index 20e1314d4..a114a1072 100644 --- a/hypervisor/arch/x86/configs/nuc7i7dnb/board.c +++ b/hypervisor/arch/x86/configs/nuc7i7dnb/board.c @@ -5,6 +5,55 @@ */ #include +#include + +static struct dmar_dev_scope drhd0_dev_scope[DRHD0_DEV_CNT] = { + { + .type = DRHD0_DEVSCOPE0_TYPE, + .id = DRHD0_DEVSCOPE0_ID, + .bus = DRHD0_DEVSCOPE0_BUS, + .devfun = DRHD0_DEVSCOPE0_PATH + }, +}; + +static struct dmar_dev_scope drhd1_dev_scope[DRHD1_DEV_CNT] = { + { + .type = DRHD1_DEVSCOPE0_TYPE, + .id = DRHD1_DEVSCOPE0_ID, + .bus = DRHD1_DEVSCOPE0_BUS, + .devfun = DRHD1_DEVSCOPE0_PATH + }, + { + .type = DRHD1_DEVSCOPE1_TYPE, + .id = DRHD1_DEVSCOPE1_ID, + .bus = DRHD1_DEVSCOPE1_BUS, + .devfun = DRHD1_DEVSCOPE1_PATH + }, +}; + +static struct dmar_drhd drhd_info_array[DRHD_COUNT] = { + { + .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 + }, +}; + +struct dmar_info plat_dmar_info = { + .drhd_count = DRHD_COUNT, + .drhd_units = drhd_info_array, +}; struct platform_clos_info platform_clos_array[0]; uint16_t platform_clos_num = 0; diff --git a/hypervisor/arch/x86/configs/nuc7i7dnb/platform_acpi_info.h b/hypervisor/arch/x86/configs/nuc7i7dnb/platform_acpi_info.h index ab4e3cf9d..45270fa66 100644 --- a/hypervisor/arch/x86/configs/nuc7i7dnb/platform_acpi_info.h +++ b/hypervisor/arch/x86/configs/nuc7i7dnb/platform_acpi_info.h @@ -43,61 +43,28 @@ #define DRHD_COUNT 2U -#define DRHD0_DEV_CNT 1U -#define DRHD0_SEGMENT 0U -#define DRHD0_FLAGS 0U +#define DRHD0_DEV_CNT 0x1U +#define DRHD0_SEGMENT 0x0U +#define DRHD0_FLAGS 0x0U #define DRHD0_REG_BASE 0xFED90000UL -#define DRHD0_IGNORE false +#define DRHD0_IGNORE true +#define DRHD0_DEVSCOPE0_TYPE 0x1U +#define DRHD0_DEVSCOPE0_ID 0x0U #define DRHD0_DEVSCOPE0_BUS 0x0U #define DRHD0_DEVSCOPE0_PATH 0x10U -#define DRHD0_DEVSCOPE1_BUS 0x0U -#define DRHD0_DEVSCOPE1_PATH 0x0U -#define DRHD0_DEVSCOPE2_BUS 0x0U -#define DRHD0_DEVSCOPE2_PATH 0x0U -#define DRHD0_DEVSCOPE3_BUS 0x0U -#define DRHD0_DEVSCOPE3_PATH 0x0U -#define DRHD1_DEV_CNT 2U -#define DRHD1_SEGMENT 0U -#define DRHD1_FLAGS 1U +#define DRHD1_DEV_CNT 0x2U +#define DRHD1_SEGMENT 0x0U +#define DRHD1_FLAGS 0x1U #define DRHD1_REG_BASE 0xFED91000UL #define DRHD1_IGNORE false +#define DRHD1_DEVSCOPE0_TYPE 0x3U +#define DRHD1_DEVSCOPE0_ID 0x2U #define DRHD1_DEVSCOPE0_BUS 0xf0U #define DRHD1_DEVSCOPE0_PATH 0xf8U +#define DRHD1_DEVSCOPE1_TYPE 0x4U +#define DRHD1_DEVSCOPE1_ID 0x0U #define DRHD1_DEVSCOPE1_BUS 0x0U #define DRHD1_DEVSCOPE1_PATH 0xf8U -#define DRHD1_DEVSCOPE2_BUS 0x0U -#define DRHD1_DEVSCOPE2_PATH 0x0U -#define DRHD1_DEVSCOPE3_BUS 0x0U -#define DRHD1_DEVSCOPE3_PATH 0x0U -#define DRHD1_IOAPIC_ID 2U - -#define DRHD2_DEV_CNT 0U -#define DRHD2_SEGMENT 0U -#define DRHD2_FLAGS 0U -#define DRHD2_REG_BASE 0x00UL -#define DRHD2_IGNORE false -#define DRHD2_DEVSCOPE0_BUS 0x0U -#define DRHD2_DEVSCOPE0_PATH 0x0U -#define DRHD2_DEVSCOPE1_BUS 0x0U -#define DRHD2_DEVSCOPE1_PATH 0x0U -#define DRHD2_DEVSCOPE2_BUS 0x0U -#define DRHD2_DEVSCOPE2_PATH 0x0U -#define DRHD2_DEVSCOPE3_BUS 0x0U -#define DRHD2_DEVSCOPE3_PATH 0x0U - -#define DRHD3_DEV_CNT 0U -#define DRHD3_SEGMENT 0U -#define DRHD3_FLAGS 0U -#define DRHD3_REG_BASE 0x00UL -#define DRHD3_IGNORE false -#define DRHD3_DEVSCOPE0_BUS 0x0U -#define DRHD3_DEVSCOPE0_PATH 0x0U -#define DRHD3_DEVSCOPE1_BUS 0x0U -#define DRHD3_DEVSCOPE1_PATH 0x0U -#define DRHD3_DEVSCOPE2_BUS 0x0U -#define DRHD3_DEVSCOPE2_PATH 0x0U -#define DRHD3_DEVSCOPE3_BUS 0x0U -#define DRHD3_DEVSCOPE3_PATH 0x0U #endif /* PLATFORM_ACPI_INFO_H */ diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index b4fb405b9..1d49c3030 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #define DBG_IOMMU 0 @@ -1329,6 +1330,18 @@ void resume_iommu(void) do_action_for_iommus(dmar_resume); } +/** + * @post return != NULL + * @post return->drhd_count > 0U + */ +static struct dmar_info *get_dmar_info(void) +{ +#ifdef CONFIG_ACPI_PARSE_ENABLED + parse_dmar_table(&plat_dmar_info); +#endif + return &plat_dmar_info; +} + int32_t init_iommu(void) { int32_t ret = 0; diff --git a/hypervisor/boot/dmar_info.c b/hypervisor/boot/dmar_info.c deleted file mode 100644 index 6dc10444b..000000000 --- a/hypervisor/boot/dmar_info.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include - -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_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 - }, -}; - -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_ACPI_PARSE_ENABLED - parse_dmar_table(&plat_dmar_info); -#endif - return &plat_dmar_info; -} diff --git a/hypervisor/include/arch/x86/board.h b/hypervisor/include/arch/x86/board.h index 25533966b..0d7cebd81 100644 --- a/hypervisor/include/arch/x86/board.h +++ b/hypervisor/include/arch/x86/board.h @@ -17,6 +17,7 @@ struct platform_clos_info { uint32_t msr_index; }; +extern struct dmar_info plat_dmar_info; extern struct platform_clos_info platform_clos_array[]; extern uint16_t platform_clos_num; extern const struct cpu_state_table board_cpu_state_tbl; diff --git a/hypervisor/include/arch/x86/vtd.h b/hypervisor/include/arch/x86/vtd.h index 2a26f0d08..ea2c14625 100644 --- a/hypervisor/include/arch/x86/vtd.h +++ b/hypervisor/include/arch/x86/vtd.h @@ -471,7 +471,7 @@ static inline uint16_t dma_frcd_up_sid(uint64_t up_sid) } #define MAX_DRHDS DRHD_COUNT -#define MAX_DRHD_DEVSCOPES 4 +#define MAX_DRHD_DEVSCOPES 16U #define DMAR_CONTEXT_TRANSLATION_TYPE_TRANSLATED 0x00U #define DMAR_CONTEXT_TRANSLATION_TYPE_RESERVED 0x01U @@ -530,8 +530,6 @@ union dmar_ir_entry { } bits __packed; }; -extern struct dmar_info *get_dmar_info(void); - #ifdef CONFIG_ACPI_PARSE_ENABLED int32_t parse_dmar_table(struct dmar_info *plat_dmar_info); #endif