Commit 099b2196e4a693968fd6205ac6d61f6eaab79fb1

Authored by Miao Yan
Committed by Bin Meng
1 parent 34865a65c4

cmd: qfw: add API to iterate firmware list

This patch is part of the refactor work of qfw. It adds 3 APIs to qfw
core to iterate firmware list.

Signed-off-by: Miao Yan <yanmiaobest@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Showing 2 changed files with 31 additions and 3 deletions Side-by-side Diff

... ... @@ -229,10 +229,27 @@
229 229 }
230 230 }
231 231  
  232 +struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter)
  233 +{
  234 + iter->entry = fw_list.next;
  235 + return list_entry(iter->entry, struct fw_file, list);
  236 +}
  237 +
  238 +struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter)
  239 +{
  240 + iter->entry = iter->entry->next;
  241 + return list_entry(iter->entry, struct fw_file, list);
  242 +}
  243 +
  244 +bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter)
  245 +{
  246 + return iter->entry == &fw_list;
  247 +}
  248 +
232 249 static int qemu_fwcfg_list_firmware(void)
233 250 {
234 251 int ret;
235   - struct list_head *entry;
  252 + struct fw_cfg_file_iter iter;
236 253 struct fw_file *file;
237 254  
238 255 /* make sure fw_list is loaded */
... ... @@ -240,8 +257,10 @@
240 257 if (ret)
241 258 return ret;
242 259  
243   - list_for_each(entry, &fw_list) {
244   - file = list_entry(entry, struct fw_file, list);
  260 +
  261 + for (file = qemu_fwcfg_file_iter_init(&iter);
  262 + !qemu_fwcfg_file_iter_end(&iter);
  263 + file = qemu_fwcfg_file_iter_next(&iter)) {
245 264 printf("%-56s\n", file->cfg.name);
246 265 }
247 266  
include/qemu_fw_cfg.h
... ... @@ -87,6 +87,10 @@
87 87 struct list_head list; /* list node to link to fw_list */
88 88 };
89 89  
  90 +struct fw_cfg_file_iter {
  91 + struct list_head *entry; /* structure to iterate file list */
  92 +};
  93 +
90 94 struct fw_cfg_dma_access {
91 95 __be32 control;
92 96 __be32 length;
... ... @@ -158,6 +162,11 @@
158 162 * @return: cpu number in system
159 163 */
160 164 int qemu_fwcfg_online_cpus(void);
  165 +
  166 +/* helper functions to iterate firmware file list */
  167 +struct fw_file *qemu_fwcfg_file_iter_init(struct fw_cfg_file_iter *iter);
  168 +struct fw_file *qemu_fwcfg_file_iter_next(struct fw_cfg_file_iter *iter);
  169 +bool qemu_fwcfg_file_iter_end(struct fw_cfg_file_iter *iter);
161 170  
162 171 #endif