Pratikkumar V Prajapati (pratikkumar.v.prajapati@intel.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17496
-gerrit
commit e38ce5a95bea4e2a2a163f9fe410b8e7517c4b90 Author: Pratik Prajapati pratikkumar.v.prajapati@intel.com Date: Fri Nov 18 14:36:34 2016 -0800
intel MMA: Enable MMA with FSP2.0
- Separate mma code for fsp1.1 and fsp2.0 and restructuring the code - common code is placed in mma.c and mma.h - mma_fsp<ver>.h and fsp<ver>/mma_core.c contains fsp version specific code. - whole MMA feature is guarded by CONFIG_MMA flag.
Change-Id: I12c9a1122ea7a52f050b852738fb95d03ce44800 Signed-off-by: Pratik Prajapati pratikkumar.v.prajapati@intel.com --- src/drivers/intel/common/Kconfig | 19 ++ src/drivers/intel/common/Makefile.inc | 19 ++ src/drivers/intel/common/include/mma.h | 55 +++++ src/drivers/intel/common/mma.c | 267 ++++++++++++++++++++++ src/drivers/intel/fsp1_1/Kconfig | 6 + src/drivers/intel/fsp1_1/Makefile.inc | 2 + src/drivers/intel/fsp1_1/include/fsp/mma_fsp11.h | 29 +++ src/drivers/intel/fsp1_1/mma_core.c | 68 ++++++ src/drivers/intel/fsp1_1/raminit.c | 10 +- src/drivers/intel/fsp2_0/Kconfig | 6 + src/drivers/intel/fsp2_0/Makefile.inc | 2 + src/drivers/intel/fsp2_0/include/fsp/mma_fsp20.h | 29 +++ src/drivers/intel/fsp2_0/memory_init.c | 8 + src/drivers/intel/fsp2_0/mma_core.c | 64 ++++++ src/soc/intel/common/Kconfig | 11 - src/soc/intel/common/Makefile.inc | 2 - src/soc/intel/common/mma.c | 273 ----------------------- src/soc/intel/common/mma.h | 23 -- 18 files changed, 581 insertions(+), 312 deletions(-)
diff --git a/src/drivers/intel/common/Kconfig b/src/drivers/intel/common/Kconfig new file mode 100644 index 0000000..4a57264 --- /dev/null +++ b/src/drivers/intel/common/Kconfig @@ -0,0 +1,19 @@ +# +# This file is part of the coreboot project. +# +# Copyright (C) 2016 Intel Corp. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +config MMA_BLOBS_PATH + string "Path to MMA blobs" + depends on MMA && ( PLATFORM_USES_FSP2_0 || PLATFORM_USES_FSP1_1 ) + default "3rdparty/blobs/mainboard/$(MAINBOARDDIR)/mma" diff --git a/src/drivers/intel/common/Makefile.inc b/src/drivers/intel/common/Makefile.inc new file mode 100644 index 0000000..e704dcc --- /dev/null +++ b/src/drivers/intel/common/Makefile.inc @@ -0,0 +1,19 @@ +# +# This file is part of the coreboot project. +# +# Copyright (C) 2016 Intel Corporation. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +ramstage-$(CONFIG_MMA) += mma.c +romstage-$(CONFIG_MMA) += mma.c + +CPPFLAGS_common += -I$(src)/drivers/intel/common/include diff --git a/src/drivers/intel/common/include/mma.h b/src/drivers/intel/common/include/mma.h new file mode 100644 index 0000000..b5fab4a --- /dev/null +++ b/src/drivers/intel/common/include/mma.h @@ -0,0 +1,55 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2016 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _SOC_MMA_H_ +#define _SOC_MMA_H_ + +struct mma_config_param; +struct mma_data_container; + +#if IS_ENABLED(CONFIG_PLATFORM_USES_FSP2_0) +#include <fsp/mma_fsp20.h> +#elif IS_ENABLED(CONFIG_PLATFORM_USES_FSP1_1) +#include <fsp/mma_fsp11.h> +#else +#error "error FSP version not defined or unsupported for MMA" +#endif + +struct mma_data_container { + uint32_t mma_signature; // "MMAD" + uint8_t mma_data[0]; // Variable size, platform/run time dependent. +} __attribute__ ((packed)); + +struct mma_config_param { + uint32_t MmaTestContentPtr; + uint32_t MmaTestContentSize; + uint32_t MmaTestConfigPtr; + uint32_t MmaTestConfigSize; + uint8_t MrcFastBoot; + uint8_t SaGv; +} __attribute__ ((packed)); + +/* Set up the MMA for execution. Locate mma files in CBFS and fill in mma_cfg + * with locations, and other settings like Fastboot, SaGv. + * Returns 0 on success, < 0 on failure. + */ +int setup_mma(struct mma_config_param *mma_cfg); +/* Locate the MMA hob from the FSP Hob list, This is implemented + * specific to FSP version. + * Returns 0 on success, < 0 on failure. + */ +int fsp_locate_mma_results(const void **mma_hob, u32 *mma_hob_size); + +#endif diff --git a/src/drivers/intel/common/mma.c b/src/drivers/intel/common/mma.c new file mode 100644 index 0000000..7f9f3bf --- /dev/null +++ b/src/drivers/intel/common/mma.c @@ -0,0 +1,267 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2016 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <bootstate.h> +#include <cbfs.h> +#include <cbmem.h> +#include <console/console.h> +#include <fsp/util.h> +#include <mma.h> + +#define MMA_TEST_METADATA_FILENAME "mma_test_metadata.bin" +#define MMA_TEST_NAME_TAG "MMA_TEST_NAME" +#define MMA_TEST_PARAM_TAG "MMA_TEST_PARAM" +#define TEST_NAME_MAX_SIZE 30 +#define TEST_PARAM_MAX_SIZE 100 +#define MMA_DATA_SIGNATURE (('M' << 0) | ('M' << 8) | \ + ('A' << 16) | ('D' << 24)) +#define MMA_CBFS_REGION "BOOT_STUB" +//#define MMA_CBFS_REGION "COREBOOT" + +/* + * Format of the MMA test metadata file, stored under CBFS + * MMA_TEST_NAME=xxxxxx.efi;MMA_TEST_PARAM=xxxxxx.bin; + */ + +/* Returns index in haystack after 'LABEL=' + * string is found, < 0 on error. + */ +static int find_label(const char *haystack, size_t haystack_sz, + const char *label) +{ + size_t label_sz; + size_t i; + size_t search_sz; + + label_sz = strlen(label); + + if (label_sz + 1 >= haystack_sz) + return -1; + + /* Handle '=' follow label. i.e. LABEL= */ + search_sz = haystack_sz - label_sz - 1; + for (i = 0; i < search_sz; i++) { + if (!strncmp(&haystack[i], label, label_sz)) + break; + } + + if (i == search_sz) + return -1; + + if (haystack[i + label_sz] != '=') + return -1; + + return i + label_sz + 1; +} + +/* + * Fill in value in dest field located by LABEL=. + * Returns 0 on success, < 0 on error. + */ +static int label_value(const char *haystack, size_t haystack_sz, + const char *label, char *dest, size_t dest_sz) +{ + size_t val_begin; + size_t val_end; + size_t val_sz; + int val_index; + + memset(dest, 0, dest_sz); + + /* Allow for NULL termination. */ + dest_sz--; + val_index = find_label(haystack, haystack_sz, label); + if (val_index < 0) + return -1; + + val_begin = val_index; + val_end = val_begin; + val_sz = 0; + + for (val_end = val_begin; val_end < haystack_sz; val_end++) { + if (haystack[val_end] == ';') { + val_sz = val_end - val_begin; + break; + } + } + + if (val_end == haystack_sz) + return -1; + + if (dest_sz < val_sz) + return -1; + + memcpy(dest, &haystack[val_begin], val_sz); + + return 0; +} + +int setup_mma(struct mma_config_param *mma_cfg) +{ + void *mma_test_metadata, *mma_test_content, *mma_test_param; + size_t mma_test_metadata_file_len, mma_test_content_file_len, + mma_test_param_file_len; + char test_filename[TEST_NAME_MAX_SIZE], + test_param_filename[TEST_PARAM_MAX_SIZE]; + struct cbfsf metadata_fh, test_content_fh, test_param_fh; + uint32_t mma_type = CBFS_TYPE_MMA; + uint32_t efi_type = CBFS_TYPE_EFI; + + printk(BIOS_DEBUG, "Entry %s\n", __func__); + + memset(&metadata_fh, 0, sizeof(metadata_fh)); + memset(&test_content_fh, 0, sizeof(test_content_fh)); + memset(&test_param_fh, 0, sizeof(test_param_fh)); + + if (cbfs_locate_file_in_region(&metadata_fh, MMA_CBFS_REGION, + MMA_TEST_METADATA_FILENAME, &mma_type)) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to locate %s\n", + MMA_TEST_METADATA_FILENAME); + return -1; + } + + mma_test_metadata_file_len = 0; + mma_test_metadata = NULL; + mma_test_metadata = rdev_mmap_full(&metadata_fh.data); + mma_test_metadata_file_len = region_device_sz(&metadata_fh.data); + + if (!mma_test_metadata || !mma_test_metadata_file_len) { + printk(BIOS_DEBUG, "MMA setup failed: Failed to read %s\n", + MMA_TEST_METADATA_FILENAME); + return -1; + } + + if (label_value(mma_test_metadata, mma_test_metadata_file_len, + MMA_TEST_NAME_TAG, test_filename, TEST_NAME_MAX_SIZE)) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to get %s\n", + MMA_TEST_NAME_TAG); + return -1; + } + + if (label_value(mma_test_metadata, mma_test_metadata_file_len, + MMA_TEST_PARAM_TAG, test_param_filename, + TEST_PARAM_MAX_SIZE)) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to get %s\n", + MMA_TEST_PARAM_TAG); + return -1; + } + + printk(BIOS_DEBUG, "Got MMA_TEST_NAME=%s MMA_TEST_PARAM=%s\n", + test_filename, test_param_filename); + + if (cbfs_locate_file_in_region(&test_content_fh, MMA_CBFS_REGION, + test_filename, &efi_type)) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to locate %s\n", + test_filename); + return -1; + } + + mma_test_content_file_len = 0; + mma_test_content = NULL; + mma_test_content = rdev_mmap_full(&test_content_fh.data); + mma_test_content_file_len = region_device_sz(&test_content_fh.data); + + if (!mma_test_content || !mma_test_content_file_len) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to read %s.\n", + test_filename); + return -1; + } + + if (cbfs_locate_file_in_region(&test_param_fh, MMA_CBFS_REGION, + test_param_filename, &mma_type)) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to locate %s\n", + test_param_filename); + return -1; + } + + mma_test_param_file_len = 0; + mma_test_param = NULL; + mma_test_param = rdev_mmap_full(&test_param_fh.data); + mma_test_param_file_len = region_device_sz(&test_param_fh.data); + + if (!mma_test_param || !mma_test_param_file_len) { + printk(BIOS_DEBUG, "MMA set up failed: Failed to read %s\n", + test_param_filename); + return -1; + } + + mma_cfg->MmaTestContentPtr = (uintptr_t) mma_test_content; + mma_cfg->MmaTestContentSize = mma_test_content_file_len; + mma_cfg->MmaTestConfigPtr = (uintptr_t) mma_test_param; + mma_cfg->MmaTestConfigSize = mma_test_param_file_len; + mma_cfg->MrcFastBoot = 0x00; + mma_cfg->SaGv = 0x02; + + printk(BIOS_DEBUG, "MMA Test name %s\n", test_filename); + printk(BIOS_DEBUG, "MMA Test Config name %s\n", test_param_filename); + printk(BIOS_DEBUG, "MMA passing following mma_cfg\n"); + printk(BIOS_DEBUG, "mma_cfg->MmaTestContentPtr = %0x\n", + mma_cfg->MmaTestContentPtr); + printk(BIOS_DEBUG, "mma_cfg->MmaTestContentSize = %d\n", + mma_cfg->MmaTestContentSize); + printk(BIOS_DEBUG, "mma_cfg->MmaTestConfigPtr = %0x\n", + mma_cfg->MmaTestConfigPtr); + printk(BIOS_DEBUG, "mma_cfg->MmaTestConfigSize = %d\n", + mma_cfg->MmaTestConfigSize); + printk(BIOS_DEBUG, "mma_cfg->MrcFastBoot = %d\n", + mma_cfg->MrcFastBoot); + printk(BIOS_DEBUG, "mma_cfg->SaGv = %d\n", + mma_cfg->SaGv); + + return 0; +} + +static void save_mma_results_data(void *unused) +{ + const void *mma_hob = NULL; + uint32_t mma_hob_size; + struct mma_data_container *mma_data; + uint32_t mma_data_size = 0; + + printk(BIOS_DEBUG, "Entry %s\n", __func__); + + if (fsp_locate_mma_results(&mma_hob, &mma_hob_size)) { + printk(BIOS_DEBUG, + "MMA results data Hob not present\n"); + return; + } + + printk(BIOS_DEBUG, "%s mma_hob = %p\n", __func__, mma_hob); + mma_data_size = ALIGN(mma_hob_size, 16) + + sizeof(struct mma_data_container); + + mma_data = cbmem_add(CBMEM_ID_MMA_DATA, mma_data_size); + + if (mma_data == NULL) { + printk(BIOS_DEBUG, + "CBMEM was not available to save the MMA data.\n"); + return; + } + + /*clear the mma_data before coping the actual data */ + memset(mma_data, 0, mma_data_size); + + printk(BIOS_DEBUG, + "Copy MMA data to CBMEM(src addr %p, dest addr %p, %u bytes)\n", + mma_hob, mma_data, mma_hob_size); + + mma_data->mma_signature = MMA_DATA_SIGNATURE; + memcpy(mma_data->mma_data, mma_hob, mma_hob_size); + + printk(BIOS_DEBUG, "Write MMA results data to cbmem success\n"); +} + +BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_ENTRY, + save_mma_results_data, NULL); diff --git a/src/drivers/intel/fsp1_1/Kconfig b/src/drivers/intel/fsp1_1/Kconfig index cc3c0a7..3e6a153 100644 --- a/src/drivers/intel/fsp1_1/Kconfig +++ b/src/drivers/intel/fsp1_1/Kconfig @@ -115,4 +115,10 @@ config RESET_ON_INVALID_RAMSTAGE_CACHE bool "Reset the system on S3 wake when ramstage cache invalid." default n
+config MMA + bool "Enable MMA (Memory Margin Analysis) support" + default n + help + Set this option to y to enable MMA (Memory Margin Analysis) support + endif #PLATFORM_USES_FSP1_1 diff --git a/src/drivers/intel/fsp1_1/Makefile.inc b/src/drivers/intel/fsp1_1/Makefile.inc index 4ea23f3..4088293 100644 --- a/src/drivers/intel/fsp1_1/Makefile.inc +++ b/src/drivers/intel/fsp1_1/Makefile.inc @@ -31,6 +31,7 @@ romstage-y += romstage.c romstage-$(CONFIG_SEPARATE_VERSTAGE) += romstage_after_verstage.S romstage-y += stack.c romstage-y += stage_cache.c +romstage-$(CONFIG_MMA) += mma_core.c
ramstage-$(CONFIG_GOP_SUPPORT) += fsp_gop.c ramstage-y += fsp_relocate.c @@ -39,6 +40,7 @@ ramstage-y += hob.c ramstage-y += ramstage.c ramstage-y += stage_cache.c ramstage-$(CONFIG_GOP_SUPPORT) += vbt.c +ramstage-$(CONFIG_MMA) += mma_core.c
CPPFLAGS_common += -Isrc/drivers/intel/fsp1_1/include
diff --git a/src/drivers/intel/fsp1_1/include/fsp/mma_fsp11.h b/src/drivers/intel/fsp1_1/include/fsp/mma_fsp11.h new file mode 100644 index 0000000..4d411f1 --- /dev/null +++ b/src/drivers/intel/fsp1_1/include/fsp/mma_fsp11.h @@ -0,0 +1,29 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2016 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _SOC_MMA_FSP11_H_ +#define _SOC_MMA_FSP11_H_ + +#include <fsp/soc_binding.h> + +void update_memory_params_for_mma(MEMORY_INIT_UPD *memory_upd, + struct mma_config_param *mma_cfg); +/* init mma. calls setup_mma to locate mma files and then updates MMA + * related memory params. + * Returns 0 on success, < 0 on failure. + */ +int mma_init(MEMORY_INIT_UPD *memory_upd); + +#endif diff --git a/src/drivers/intel/fsp1_1/mma_core.c b/src/drivers/intel/fsp1_1/mma_core.c new file mode 100644 index 0000000..c892a6a --- /dev/null +++ b/src/drivers/intel/fsp1_1/mma_core.c @@ -0,0 +1,68 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2016 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <console/console.h> +#include <fsp/util.h> +#include <mma.h> +#include <string.h> + +#define FSP_MMA_RESULTS_GUID { 0x8f4e928, 0xf5f, 0x46d4, \ + { 0x84, 0x10, 0x47, 0x9f, 0xda, 0x27, 0x9d, 0xb6 } } + +int fsp_locate_mma_results(const void **mma_hob, uint32_t *mma_hob_size) +{ + const void *mma_hob_start; + const EFI_GUID mma_results_guid = FSP_MMA_RESULTS_GUID; + + mma_hob_start = get_first_guid_hob(&mma_results_guid); + if (!mma_hob_start) + return -1; + *mma_hob = GET_GUID_HOB_DATA(mma_hob_start); + *mma_hob_size = GET_HOB_LENGTH(mma_hob); + + printk(BIOS_DEBUG, "%s mma_hob = %p\n", __func__, *mma_hob); + + if (!(*mma_hob_size) || !(*mma_hob)) + return -1; + return 0; +} + +void update_memory_params_for_mma(MEMORY_INIT_UPD *memory_upd, + struct mma_config_param *mma_cfg) +{ + memory_upd->MmaTestContentPtr = mma_cfg->MmaTestContentPtr; + memory_upd->MmaTestContentSize = mma_cfg->MmaTestContentSize; + memory_upd->MmaTestConfigPtr = mma_cfg->MmaTestConfigPtr; + memory_upd->MmaTestConfigSize = mma_cfg->MmaTestConfigSize; + memory_upd->MrcFastBoot = 0x00; + memory_upd->SaGv = 0x02; +} + +int mma_init(MEMORY_INIT_UPD *memory_upd) +{ + struct mma_config_param mma_cfg; + + memset(&mma_cfg, 0, sizeof(mma_cfg)); + if (setup_mma(&mma_cfg)) { + printk(BIOS_DEBUG, "%s", + "MMA set up failed, not updating memory params\n"); + return -1; + } + + update_memory_params_for_mma(memory_upd, &mma_cfg); + printk(BIOS_DEBUG, "MMA set up successfully, updated memory params\n"); + + return 0; +} diff --git a/src/drivers/intel/fsp1_1/raminit.c b/src/drivers/intel/fsp1_1/raminit.c index eca8934..467eb31 100644 --- a/src/drivers/intel/fsp1_1/raminit.c +++ b/src/drivers/intel/fsp1_1/raminit.c @@ -21,7 +21,7 @@ #include <fsp/util.h> #include <lib.h> /* hexdump */ #include <reset.h> -#include <soc/intel/common/mma.h> +#include <mma.h> #include <string.h> #include <timestamp.h> #include <vboot/vboot_common.h> @@ -101,8 +101,12 @@ void raminit(struct romstage_params *params) soc_memory_init_params(params, &memory_init_params); mainboard_memory_init_params(params, &memory_init_params);
- if (IS_ENABLED(CONFIG_MMA)) - setup_mma(&memory_init_params); + if (IS_ENABLED(CONFIG_MMA)) { + if (mma_init(&memory_init_params)) + printk(BIOS_DEBUG, "MMA init completed sucussfully\n"); + else + printk(BIOS_DEBUG, "MMA init failed\n"); + }
post_code(0x36);
diff --git a/src/drivers/intel/fsp2_0/Kconfig b/src/drivers/intel/fsp2_0/Kconfig index 4f40c3f..2667728 100644 --- a/src/drivers/intel/fsp2_0/Kconfig +++ b/src/drivers/intel/fsp2_0/Kconfig @@ -100,4 +100,10 @@ config FSP2_0_USES_TPM_MRC_HASH default n select VBOOT_HAS_REC_HASH_SPACE
+config MMA + bool "Enable MMA (Memory Margin Analysis) support for Intel Core" + default n + help + Set this option to y to enable MMA (Memory Margin Analysis) support + endif diff --git a/src/drivers/intel/fsp2_0/Makefile.inc b/src/drivers/intel/fsp2_0/Makefile.inc index beeec7c..ad654b9 100644 --- a/src/drivers/intel/fsp2_0/Makefile.inc +++ b/src/drivers/intel/fsp2_0/Makefile.inc @@ -24,6 +24,7 @@ romstage-$(CONFIG_VERIFY_HOBS) += hob_verify.c romstage-y += util.c romstage-y += memory_init.c romstage-$(CONFIG_CACHE_RELOCATED_RAMSTAGE_OUTSIDE_CBMEM) += stage_cache.c +romstage-$(CONFIG_MMA) += mma_core.c
ramstage-y += debug.c ramstage-y += graphics.c @@ -36,6 +37,7 @@ ramstage-y += silicon_init.c ramstage-$(CONFIG_CACHE_RELOCATED_RAMSTAGE_OUTSIDE_CBMEM) += stage_cache.c ramstage-$(CONFIG_DISPLAY_UPD_DATA) += upd_display.c ramstage-y += util.c +ramstage-$(CONFIG_MMA) += mma_core.c
postcar-$(CONFIG_CACHE_RELOCATED_RAMSTAGE_OUTSIDE_CBMEM) += stage_cache.c
diff --git a/src/drivers/intel/fsp2_0/include/fsp/mma_fsp20.h b/src/drivers/intel/fsp2_0/include/fsp/mma_fsp20.h new file mode 100644 index 0000000..b295f9c --- /dev/null +++ b/src/drivers/intel/fsp2_0/include/fsp/mma_fsp20.h @@ -0,0 +1,29 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2016 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _SOC_MMA_FSP20_H_ +#define _SOC_MMA_FSP20_H_ + +#include <fsp/soc_binding.h> + +void update_memory_params_for_mma(FSP_M_CONFIG *memory_cfg, + struct mma_config_param *mma_cfg); +/* init mma. calls setup_mma to locate mma files and then updates MMA + * related memory params. + * Returns 0 on success, < 0 on failure. + */ +int mma_init(FSP_M_CONFIG *memory_cfg); + +#endif diff --git a/src/drivers/intel/fsp2_0/memory_init.c b/src/drivers/intel/fsp2_0/memory_init.c index b833561..5e0e32a 100644 --- a/src/drivers/intel/fsp2_0/memory_init.c +++ b/src/drivers/intel/fsp2_0/memory_init.c @@ -22,6 +22,7 @@ #include <fsp/api.h> #include <fsp/util.h> #include <memrange.h> +#include <mma.h> #include <program_loading.h> #include <reset.h> #include <romstage_handoff.h> @@ -318,6 +319,13 @@ static void do_fsp_memory_init(struct fsp_header *hdr, bool s3wake, /* Give SoC and mainboard a chance to update the UPD */ platform_fsp_memory_init_params_cb(&fspm_upd);
+ if (IS_ENABLED(CONFIG_MMA)) { + if (mma_init(&fspm_upd.FspmConfig)) + printk(BIOS_DEBUG, "MMA init failed\n"); + else + printk(BIOS_DEBUG, "MMA init completed sucussfully\n"); + } + /* Call FspMemoryInit */ fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset); fsp_debug_before_memory_init(fsp_raminit, upd, &fspm_upd); diff --git a/src/drivers/intel/fsp2_0/mma_core.c b/src/drivers/intel/fsp2_0/mma_core.c new file mode 100644 index 0000000..1c77ed1 --- /dev/null +++ b/src/drivers/intel/fsp2_0/mma_core.c @@ -0,0 +1,64 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2016 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <console/console.h> +#include <fsp/util.h> +#include <mma.h> +#include <string.h> + +static const uint8_t mma_results_uuid[16] = { 0x28, 0xe9, 0xf4, 0x08, + 0x5f, 0x0f, 0xd4, 0x46, + 0x84, 0x10, 0x47, 0x9f, 0xda, 0x27, 0x9d, 0xb6 }; + +int fsp_locate_mma_results(const void **mma_hob, uint32_t *mma_hob_size) +{ + *mma_hob_size = 0; + *mma_hob = fsp_find_extension_hob_by_guid(mma_results_uuid, + mma_hob_size); + printk(BIOS_DEBUG, "%s mma_hob = %p\n", __func__, *mma_hob); + + if (!(*mma_hob_size) || !(*mma_hob)) + return -1; + return 0; +} + +void update_memory_params_for_mma(FSP_M_CONFIG *memory_cfg, + struct mma_config_param *mma_cfg) +{ + memory_cfg->MmaTestContentPtr = mma_cfg->MmaTestContentPtr; + memory_cfg->MmaTestContentSize = mma_cfg->MmaTestContentSize; + memory_cfg->MmaTestConfigPtr = mma_cfg->MmaTestConfigPtr; + memory_cfg->MmaTestConfigSize = mma_cfg->MmaTestConfigSize; + memory_cfg->MrcFastBoot = 0x00; + memory_cfg->SaGv = 0x02; +} + +int mma_init(FSP_M_CONFIG *memory_cfg) +{ + struct mma_config_param mma_cfg; + + memset(&mma_cfg, 0, sizeof(mma_cfg)); + + if (setup_mma(&mma_cfg)) { + printk(BIOS_DEBUG, "%s", + "MMA set up failed, not updating memory params\n"); + return -1; + } + + update_memory_params_for_mma(memory_cfg, &mma_cfg); + printk(BIOS_DEBUG, "MMA set up successfully, updated memory params\n"); + + return 0; +} diff --git a/src/soc/intel/common/Kconfig b/src/soc/intel/common/Kconfig index 5d8bf66..fb4b3d4 100644 --- a/src/soc/intel/common/Kconfig +++ b/src/soc/intel/common/Kconfig @@ -78,17 +78,6 @@ config SOC_INTEL_COMMON_LPSS_I2C_DEBUG Enable debug output for I2C transactions. This can be useful when debugging I2C drivers.
-config MMA - bool "enable MMA (Memory Margin Analysis) support" - default n - help - Set this option to y to enable MMA (Memory Margin Analysis) support - -config MMA_BLOBS_PATH - string "Path to MMA blobs" - depends on MMA - default "3rdparty/blobs/mainboard/$(MAINBOARDDIR)/mma" - config ADD_VBT_DATA_FILE bool "Add a Video Bios Table (VBT) binary to CBFS" help diff --git a/src/soc/intel/common/Makefile.inc b/src/soc/intel/common/Makefile.inc index 38903a0..7cf32bf 100644 --- a/src/soc/intel/common/Makefile.inc +++ b/src/soc/intel/common/Makefile.inc @@ -12,7 +12,6 @@ romstage-$(CONFIG_CACHE_MRC_SETTINGS) += mrc_cache.c romstage-$(CONFIG_SOC_INTEL_COMMON_LPSS_I2C) += lpss_i2c.c romstage-$(CONFIG_SOC_INTEL_COMMON_RESET) += reset.c romstage-y += util.c -romstage-$(CONFIG_MMA) += mma.c
postcar-y += util.c postcar-$(CONFIG_SOC_INTEL_COMMON_RESET) += reset.c @@ -24,7 +23,6 @@ ramstage-$(CONFIG_SOC_INTEL_COMMON_SPI_PROTECT) += spi.c ramstage-$(CONFIG_SOC_INTEL_COMMON_LPSS_I2C) += lpss_i2c.c ramstage-$(CONFIG_SOC_INTEL_COMMON_RESET) += reset.c ramstage-y += util.c -ramstage-$(CONFIG_MMA) += mma.c ramstage-$(CONFIG_SOC_INTEL_COMMON_ACPI_WAKE_SOURCE) += acpi_wake_source.c ramstage-y += vbt.c ramstage-$(CONFIG_SOC_INTEL_COMMON_GFX_OPREGION) += opregion.c diff --git a/src/soc/intel/common/mma.c b/src/soc/intel/common/mma.c deleted file mode 100644 index 87d8e5c..0000000 --- a/src/soc/intel/common/mma.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright (C) 2015 Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include <boot/coreboot_tables.h> -#include <bootstate.h> -#include <cbfs.h> -#include <cbmem.h> -#include <console/console.h> -#include <lib.h> -#include "mma.h" -#include <soc/romstage.h> -#include <string.h> -#include <fmap.h> - -#define MMA_TEST_METADATA_FILENAME "mma_test_metadata.bin" -#define MMA_TEST_NAME_TAG "MMA_TEST_NAME" -#define MMA_TEST_PARAM_TAG "MMA_TEST_PARAM" -#define MMA_CBFS_REGION "COREBOOT" -#define TEST_NAME_MAX_SIZE 30 -#define TEST_PARAM_MAX_SIZE 100 -#define FSP_MMA_RESULTS_GUID { 0x8f4e928, 0xf5f, 0x46d4, \ - { 0x84, 0x10, 0x47, 0x9f, 0xda, 0x27, 0x9d, 0xb6 } } -#define MMA_DATA_SIGNATURE (('M'<<0)|('M'<<8)|('A'<<16)|('D'<<24)) - -struct mma_data_container { - u32 mma_signature; // "MMAD" - u8 mma_data[0]; // Variable size, platform/run time dependent. -} __attribute__ ((packed)); - -/* -Format of the MMA test metadata file, stored under CBFS -MMA_TEST_NAME=xxxxxx.efi;MMA_TEST_PARAM=xxxxxx.bin; -*/ - -/* Returns index in haystack after 'LABEL=' string is found, < 0 on error. */ -static int find_label(const char *haystack, size_t haystack_sz, - const char *label) -{ - size_t label_sz; - size_t i; - size_t search_sz; - - label_sz = strlen(label); - - if (label_sz + 1 >= haystack_sz) - return -1; - - /* Handle '=' follow label. i.e. LABEL= */ - search_sz = haystack_sz - label_sz - 1; - for (i = 0; i < search_sz; i++) { - if (!strncmp(&haystack[i], label, label_sz)) - break; - } - - if (i == search_sz) - return -1; - - if (haystack[i + label_sz] != '=') - return -1; - - return i + label_sz + 1; -} -/* - * Fill in value in dest field located by LABEL=. - * Returns 0 on success, < 0 on error. - */ -static int label_value(const char *haystack, size_t haystack_sz, - const char *label, char *dest, size_t dest_sz) -{ - size_t val_begin; - size_t val_end; - size_t val_sz; - int val_index; - - memset(dest, 0, dest_sz); - - /* Allow for NULL termination. */ - dest_sz--; - val_index = find_label(haystack, haystack_sz, label); - if (val_index < 0) - return -1; - - val_begin = val_index; - val_end = val_begin; - val_sz = 0; - - for (val_end = val_begin; val_end < haystack_sz; val_end++) { - if (haystack[val_end] == ';') { - val_sz = val_end - val_begin; - break; - } - } - - if (val_end == haystack_sz) - return -1; - - if (dest_sz < val_sz) - return -1; - - memcpy(dest, &haystack[val_begin], val_sz); - - return 0; -} - -static void *cbfs_locate_file_in_region(const char *region_name, const char *file_name, - uint32_t file_type, uint32_t *file_size) -{ - struct region_device rdev; - struct cbfsf fh; - - if (file_size != NULL) - *file_size = 0; - - if (fmap_locate_area_as_rdev(region_name, &rdev) == 0) { - if (cbfs_locate(&fh, &rdev, file_name, &file_type) == 0) { - if (file_size != NULL) - *file_size = region_device_sz(&fh.data); - return rdev_mmap_full(&fh.data); - } else - printk(BIOS_DEBUG, "%s file not found in %s region\n", - file_name, region_name); - } else - printk(BIOS_DEBUG,"%s region not found while looking for %s\n", region_name, - file_name); - - return NULL; -} - -void setup_mma(MEMORY_INIT_UPD *memory_params) -{ - void *mma_test_metadata, *mma_test_content, *mma_test_param; - size_t mma_test_metadata_file_len, mma_test_content_file_len, - mma_test_param_file_len; - char test_filename[TEST_NAME_MAX_SIZE], - test_param_filename[TEST_PARAM_MAX_SIZE]; - - printk(BIOS_DEBUG, "Entry setup_mma\n"); - - memory_params->MmaTestContentPtr = 0; - memory_params->MmaTestContentSize = 0; - memory_params->MmaTestConfigPtr = 0; - memory_params->MmaTestConfigSize = 0; - - mma_test_metadata = cbfs_locate_file_in_region(MMA_CBFS_REGION, - MMA_TEST_METADATA_FILENAME, CBFS_TYPE_MMA, - &mma_test_metadata_file_len); - - if (!mma_test_metadata) { - printk(BIOS_DEBUG, "MMA setup failed: Failed to read %s\n", - MMA_TEST_METADATA_FILENAME); - return; - } - - if (label_value(mma_test_metadata, mma_test_metadata_file_len, - MMA_TEST_NAME_TAG, test_filename, TEST_NAME_MAX_SIZE)) { - printk(BIOS_DEBUG, "MMA setup failed : Failed to get %s", - MMA_TEST_NAME_TAG); - return; - } - - if (label_value(mma_test_metadata, mma_test_metadata_file_len, - MMA_TEST_PARAM_TAG, test_param_filename, - TEST_PARAM_MAX_SIZE)) { - printk(BIOS_DEBUG, "MMA setup failed : Failed to get %s", - MMA_TEST_PARAM_TAG); - return; - } - - printk(BIOS_DEBUG, "Got MMA_TEST_NAME=%s MMA_TEST_PARAM=%s\n", - test_filename, test_param_filename); - - mma_test_content = cbfs_locate_file_in_region(MMA_CBFS_REGION, - test_filename, CBFS_TYPE_EFI, - &mma_test_content_file_len); - if (!mma_test_content) { - printk(BIOS_DEBUG, "MMA setup failed: Failed to read %s.\n", - test_filename); - return; - } - - mma_test_param = cbfs_locate_file_in_region(MMA_CBFS_REGION, - test_param_filename, CBFS_TYPE_MMA, - &mma_test_param_file_len); - if (!mma_test_param) { - printk(BIOS_DEBUG, "MMA setup failed: Failed to read %s.\n", - test_param_filename); - return; - } - - memory_params->MmaTestContentPtr = (uintptr_t) mma_test_content; - memory_params->MmaTestContentSize = mma_test_content_file_len; - memory_params->MmaTestConfigPtr = (uintptr_t) mma_test_param; - memory_params->MmaTestConfigSize = mma_test_param_file_len; - memory_params->MrcFastBoot = 0x00; - memory_params->SaGv = 0x02; - - printk(BIOS_DEBUG, "MMA Test name %s\n", test_filename); - printk(BIOS_DEBUG, "MMA Test Config name %s\n", test_param_filename); - printk(BIOS_DEBUG, "MMA passing following memory_params\n"); - printk(BIOS_DEBUG, "memory_params->MmaTestContentPtr = %0x\n", - memory_params->MmaTestContentPtr); - printk(BIOS_DEBUG, "memory_params->MmaTestContentSize = %d\n", - memory_params->MmaTestContentSize); - printk(BIOS_DEBUG, "memory_params->MmaTestConfigPtr = %0x\n", - memory_params->MmaTestConfigPtr); - printk(BIOS_DEBUG, "memory_params->MmaTestConfigSize = %d\n", - memory_params->MmaTestConfigSize); - printk(BIOS_DEBUG, "memory_params->MrcFastBoot = %d\n", - memory_params->MrcFastBoot); - printk(BIOS_DEBUG, "memory_params->SaGv = %d\n", - memory_params->SaGv); - - printk(BIOS_DEBUG, "MMA setup successfully\n"); -} - -static void save_mma_results_data(void *unused) -{ - void *mma_results_hob; - u32 mma_hob_size; - u32 *mma_hob_data; - struct mma_data_container *mma_data; - int cbmem_size; - - const EFI_GUID mma_results_guid = FSP_MMA_RESULTS_GUID; - - printk(BIOS_DEBUG, "Entry save_mma_results_data MMA save data.\n"); - - mma_results_hob = get_first_guid_hob(&mma_results_guid); - if (mma_results_hob == NULL) { - printk(BIOS_DEBUG, - "MMA results data Hob not present\n"); - return; - } - - mma_hob_data = GET_GUID_HOB_DATA(mma_results_hob); - mma_hob_size = GET_HOB_LENGTH(mma_results_hob); - cbmem_size = ALIGN(mma_hob_size, 16) + - sizeof(struct mma_data_container); - mma_data = cbmem_add(CBMEM_ID_MMA_DATA, cbmem_size); - - if (mma_data == NULL) { - printk(BIOS_DEBUG, - "CBMEM was not available to save the MMA data.\n"); - return; - } - - /*clear the mma_data before coping the actual data */ - memset(mma_data, 0, cbmem_size); - - printk(BIOS_DEBUG, - "Copy MMA DATA to HOB(src addr %p, dest addr %p, %u bytes)\n", - mma_hob_data, mma_data, mma_hob_size); - - mma_data->mma_signature = MMA_DATA_SIGNATURE; - memcpy(mma_data->mma_data, mma_hob_data, mma_hob_size); - - printk(BIOS_DEBUG, "write MMA results data to cbmem success\n"); -} - -BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_ENTRY, - save_mma_results_data, NULL); diff --git a/src/soc/intel/common/mma.h b/src/soc/intel/common/mma.h deleted file mode 100644 index f1c91e2..0000000 --- a/src/soc/intel/common/mma.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is part of the coreboot project. - * - * Copyright (C) 2015 Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef _SOC_MMA_H_ -#define _SOC_MMA_H_ - -#include <fsp/soc_binding.h> - -void setup_mma(MEMORY_INIT_UPD *memory_params); - -#endif