From 4b871c6314cbd75692e74d1a91ca43719aa03b8c Mon Sep 17 00:00:00 2001 From: Wonkyu Kim Date: Wed, 9 Apr 2025 09:52:44 -0700 Subject: [PATCH] ec/intel: read board ID one time from EC per stage Use a static variable to cache the board ID. It optimizes boot time by reading the ID once per stage and retaining it for subsequent use. Rewrite the function to avoid the unnecessary ChromeEC wrapper function. Signed-off-by: Wonkyu Kim Change-Id: I166ca1abdf7838f91319d0bcf11354055ed93eef Reviewed-on: https://review.coreboot.org/c/coreboot/+/87247 Reviewed-by: Maximilian Brune Reviewed-by: Angel Pons Reviewed-by: Bora Guvendik Tested-by: build bot (Jenkins) --- src/ec/intel/board_id.c | 53 ++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/ec/intel/board_id.c b/src/ec/intel/board_id.c index 72d74c51f0..028c4e103e 100644 --- a/src/ec/intel/board_id.c +++ b/src/ec/intel/board_id.c @@ -2,32 +2,47 @@ #include #include "board_id.h" +#include #include #include #include -static uint32_t get_board_id_via_ext_ec(void) +static int intel_ec_get_board_version(uint32_t *id) { - uint32_t id = BOARD_ID_INIT; + if (send_ec_command(EC_FAB_ID_CMD)) + return -1; - if (google_chromeec_get_board_version(&id)) + *id = recv_ec_data() << 8 | recv_ec_data(); + return 0; +} + +/* Read Board ID from EC */ +int get_rvp_board_id(void) +{ + static uint32_t id = BOARD_ID_INIT; + const char *ec_type; + int ret; + + /* If already initialized, return the cached board ID. */ + if (id != BOARD_ID_INIT) + return id; + + /* Reading board ID. */ + if (CONFIG(EC_GOOGLE_CHROMEEC)) { /* Chrome EC */ + ec_type = "ChromeEC"; + ret = google_chromeec_get_board_version(&id); + } else { /* Intel EC */ + ec_type = "IntelEC"; + ret = intel_ec_get_board_version(&id); + } + + if (ret == -1) { id = BOARD_ID_UNKNOWN; + printk(BIOS_INFO, "[%s] board id: unknown\n", ec_type); + } else { + id &= BOARD_ID_MASK; + printk(BIOS_INFO, "[%s] board id: 0x%x\n", ec_type, id); + } return id; } - -/* Get Board ID via EC I/O port write/read */ -int get_rvp_board_id(void) -{ - static int id = BOARD_ID_UNKNOWN; - - if (CONFIG(EC_GOOGLE_CHROMEEC)) { /* CHROME_EC */ - id = get_board_id_via_ext_ec(); - } else { /* WINDOWS_EC */ - if (send_ec_command(EC_FAB_ID_CMD) == 0) { - id = recv_ec_data() << 8; - id |= recv_ec_data(); - } - } - return (id & BOARD_ID_MASK); -}