vendorcode/siemens: Cache currently opened hwi file name

On every call of hwilib_find_blocks() the CBFS file will be mapped and
the contents are parsed to get the offsets for every single block. This
is not needed if the CBFS file name is the same for the different calls.

This patch adds a storage for the currently opened CBFS file name in
CAR_GLOBAL and checks on each call if the file to open is already open.
If yes, the file will not be mapped again which saves execution time.

Test=Booted mc_tcu3, mc_bdx1 and mc_apl1 and verified that hwinfo.hex
is only mapped once across several following hwilib_find_blocks() calls.
In addition a test was done to ensure that files with different names
get mapped correctly.

Change-Id: Id69e0f6c914c2b8e4551fd8a4fb7d452d176afb3
Signed-off-by: Werner Zeh <werner.zeh@siemens.com>
Reviewed-on: https://review.coreboot.org/c/31518
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
This commit is contained in:
Werner Zeh 2019-02-20 06:38:04 +01:00
parent 87abccdd89
commit d35a4811db
1 changed files with 19 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This file is part of the coreboot project. * This file is part of the coreboot project.
* *
* Copyright (C) 2014 Siemens AG * Copyright (C) 2014-2019 Siemens AG
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -39,6 +39,7 @@
#define EIB_FEATRUE_OFFSET 0x00e #define EIB_FEATRUE_OFFSET 0x00e
#define LEN_MAGIC_NUM 0x007 #define LEN_MAGIC_NUM 0x007
#define BLOCK_MAGIC "H1W2M3I" #define BLOCK_MAGIC "H1W2M3I"
#define HWI_MAX_NAME_LEN 32
/* Define all supported block types. */ /* Define all supported block types. */
enum { enum {
@ -79,6 +80,9 @@ static uint8_t *all_blocks[MAX_BLOCK_NUM] CAR_GLOBAL;
*/ */
static uint16_t all_blk_size[MAX_BLOCK_NUM] CAR_GLOBAL; static uint16_t all_blk_size[MAX_BLOCK_NUM] CAR_GLOBAL;
/* Storage for the cbfs file name of the currently open hwi file. */
static char current_hwi[HWI_MAX_NAME_LEN] CAR_GLOBAL;
static uint32_t hwilib_read_bytes (const struct param_info *param, uint8_t *dst, static uint32_t hwilib_read_bytes (const struct param_info *param, uint8_t *dst,
uint32_t maxlen); uint32_t maxlen);
@ -469,11 +473,21 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
uint32_t next_offset = 1; uint32_t next_offset = 1;
uint8_t **blk_ptr = car_get_var_ptr(&all_blocks[0]); uint8_t **blk_ptr = car_get_var_ptr(&all_blocks[0]);
uint16_t *all_blk_size_ptr = car_get_var_ptr(&all_blk_size[0]); uint16_t *all_blk_size_ptr = car_get_var_ptr(&all_blk_size[0]);
char *curr_hwi_name_ptr = car_get_var_ptr(&current_hwi);
size_t filesize = 0; size_t filesize = 0;
/* Check for a valid parameter */ /* Check for a valid parameter */
if (!hwi_filename) if (!hwi_filename)
return CB_ERR_ARG; return CB_ERR_ARG;
/* Check if this file is already open. If yes, just leave as there is
nothing left to do here. */
if (curr_hwi_name_ptr &&
!strncmp(curr_hwi_name_ptr, hwi_filename, HWI_MAX_NAME_LEN)) {
printk(BIOS_SPEW, "HWILIB: File \"%s\" already open.\n",
hwi_filename);
return CB_SUCCESS;
}
ptr = cbfs_boot_map_with_leak(hwi_filename, CBFS_TYPE_RAW, &filesize); ptr = cbfs_boot_map_with_leak(hwi_filename, CBFS_TYPE_RAW, &filesize);
if (!ptr) { if (!ptr) {
printk(BIOS_ERR,"HWILIB: Missing file \"%s\" in cbfs.\n", printk(BIOS_ERR,"HWILIB: Missing file \"%s\" in cbfs.\n",
@ -533,8 +547,11 @@ enum cb_err hwilib_find_blocks (const char *hwi_filename)
} }
/* We should have found at least one valid block */ /* We should have found at least one valid block */
if (blk_ptr[BLK_HIB] || blk_ptr[BLK_SIB] || blk_ptr[BLK_EIB] || if (blk_ptr[BLK_HIB] || blk_ptr[BLK_SIB] || blk_ptr[BLK_EIB] ||
blk_ptr[BLK_XIB]) blk_ptr[BLK_XIB]) {
/* Save currently opened hwi filename. */
strncpy(curr_hwi_name_ptr, hwi_filename, HWI_MAX_NAME_LEN);
return CB_SUCCESS; return CB_SUCCESS;
}
else else
return CB_ERR; return CB_ERR;
} }