From ea31c63917a728086d70de1221e64b2a1a6225c8 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Wed, 17 Apr 2019 11:14:32 -0700 Subject: CBI: Allow board to compose data from other sources Currently, the source of CBI data is only EEPROM. This patch allows CBI data to be composed from other sources such as ADC or some chip register. cbi_board_override is called by CBI library when data is being requested. Boards can implement this callback to add additional bits or bytes to the data. A board itself may need to get CBI data first to manipulate data properly. For such a case, a board can return EC_ERROR_BUSY to inform the callers that the data is not fully ready while a board itself can accept EC_ERROR_BUSY as an expected value. Signed-off-by: Daisuke Nojiri BUG=b/129569858 BRANCH=none TEST=Read LCM_ID properly Change-Id: Ie1f962c64c8d1461a6c171bc6c6d0c855c82e945 Reviewed-on: https://chromium-review.googlesource.com/1572439 Commit-Ready: YH Lin Tested-by: Daisuke Nojiri Reviewed-by: Aseda Aboagye Reviewed-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1576626 Reviewed-by: YH Lin Commit-Queue: YH Lin Tested-by: YH Lin --- common/cbi.c | 9 ++++++++- include/cros_board_info.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/common/cbi.c b/common/cbi.c index 06e0d464c1..d8feee3189 100644 --- a/common/cbi.c +++ b/common/cbi.c @@ -154,6 +154,12 @@ static int read_board_info(void) return cached_read_result; } +__attribute__((weak)) +int cbi_board_override(enum cbi_data_tag tag, uint8_t *buf, uint8_t *size) +{ + return EC_SUCCESS; +} + int cbi_get_board_info(enum cbi_data_tag tag, uint8_t *buf, uint8_t *size) { const struct cbi_data *d; @@ -174,7 +180,8 @@ int cbi_get_board_info(enum cbi_data_tag tag, uint8_t *buf, uint8_t *size) /* Copy the value */ memcpy(buf, d->value, d->size); *size = d->size; - return EC_SUCCESS; + + return cbi_board_override(tag, buf, size); } static void cbi_remove_tag(void *const cbi, struct cbi_data *const d) diff --git a/include/cros_board_info.h b/include/cros_board_info.h index e7a1f1bb48..7650cfc078 100644 --- a/include/cros_board_info.h +++ b/include/cros_board_info.h @@ -46,6 +46,7 @@ struct cbi_data { * * @param version/sku_id/oem_id [OUT] Data read from EEPROM * @return EC_SUCCESS on success or EC_ERROR_* otherwise. + * EC_ERROR_BUSY to indicate data is not ready. */ int cbi_get_board_version(uint32_t *version); int cbi_get_sku_id(uint32_t *sku_id); @@ -53,14 +54,24 @@ int cbi_get_oem_id(uint32_t *oem_id); int cbi_get_model_id(uint32_t *id); /** - * Primitive accessors + * Get data from CBI store * * @param tag Tag of the target data. * @param buf Buffer where data is passed. * @param size (IN) Size of . (OUT) Size of the data returned. * @return EC_SUCCESS on success or EC_ERROR_* otherwise. + * EC_ERROR_BUSY to indicate data is not ready. */ int cbi_get_board_info(enum cbi_data_tag tag, uint8_t *buf, uint8_t *size); + +/** + * Set data in CBI store + * + * @param tag Tag of the target data. + * @param buf Buffer where data is passed. + * @param size (IN) Size of . (OUT) Size of the data returned. + * @return EC_SUCCESS on success or EC_ERROR_* otherwise. + */ int cbi_set_board_info(enum cbi_data_tag tag, const uint8_t *buf, uint8_t size); /* @@ -114,4 +125,21 @@ uint8_t *cbi_set_string(uint8_t *p, enum cbi_data_tag tag, const char *str); */ struct cbi_data *cbi_find_tag(const void *cbi, enum cbi_data_tag tag); +/** + * Callback implemented by board to manipulate data + * + * Note that this is part of the APIs (cbi_get_*) which can be called in any + * order any time. Your callback should return EC_SUCCESS only after it has all + * the data needed for manipulation. Until then, it should return EC_ERROR_BUSY. + * That'll provide a consistent view to the callers, which is critical for CBI + * to be functional. + * + * @param tag Tag of the data field to be manipulated + * @param buf Pointer to the buffer containing the data being manipulated. + * @param size size of the date in bytes + * @return EC_SUCCESS to indicate the data is ready. + * EC_ERROR_BUSY to indicate supplemental data is not ready. + */ +int cbi_board_override(enum cbi_data_tag tag, uint8_t *buf, uint8_t *size); + #endif /* __CROS_EC_CROS_BOARD_INFO_H */ -- cgit v1.2.1