From 34c31508989e59df42ac94558179df9fb862d791 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Mon, 20 Feb 2023 22:30:37 +0000 Subject: [PATCH] fel: introduce get_next_soc() At the moment we can search for a specific SoC in our supported SoC table by looking for its SoC ID, but we cannot otherwise enumerate all supported SoCs. Add a get_next_soc() function that allows iterating over our (internal) table: The first call will take NULL as an argument, subsequent calls pass in the pointer returned by the previous call. When we reach the end of the list, the function returns NULL. Signed-off-by: Andre Przywara --- soc_info.c | 27 +++++++++++++++++++++++++++ soc_info.h | 1 + 2 files changed, 28 insertions(+) diff --git a/soc_info.c b/soc_info.c index 501c293..08dd2cd 100644 --- a/soc_info.c +++ b/soc_info.c @@ -590,6 +590,33 @@ soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf) return get_soc_info_from_id(buf->soc_id); } +/* + * Iterate through all supported SoCs. The first call will take NULL as + * an argument, subsequent calls pass in the pointer returned by the + * previous call. When we reach the end of the list, the function + * returns NULL. + */ +const soc_info_t *get_next_soc(const soc_info_t *prev) +{ + const soc_info_t *soc; + + if (prev == NULL) + return &soc_info_table[0]; + + for (soc = soc_info_table; soc->swap_buffers; soc++) { + if (soc != prev) + continue; + + soc++; + if (!soc->swap_buffers) /* end of list? */ + return NULL; + + return soc; + } + + return NULL; /* prev entry not found */ +} + void get_soc_name_from_id(soc_name_t buffer, uint32_t soc_id) { soc_info_t *soc; diff --git a/soc_info.h b/soc_info.h index 1e72ecb..508f29d 100644 --- a/soc_info.h +++ b/soc_info.h @@ -143,5 +143,6 @@ typedef struct { void get_soc_name_from_id(soc_name_t buffer, uint32_t soc_id); soc_info_t *get_soc_info_from_id(uint32_t soc_id); soc_info_t *get_soc_info_from_version(struct aw_fel_version *buf); +const soc_info_t *get_next_soc(const soc_info_t *prev); #endif /* _SUNXI_TOOLS_SOC_INFO_H */