1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
4 * (C) Copyright 2021 Asherah Connor <ashe@kivikakk.ee>
12 int qfw_get_dev(struct udevice **devp)
14 return uclass_first_device_err(UCLASS_QFW, devp);
17 int qfw_online_cpus(struct udevice *dev)
21 qfw_read_entry(dev, FW_CFG_NB_CPUS, 2, &nb_cpus);
23 return le16_to_cpu(nb_cpus);
26 int qfw_read_firmware_list(struct udevice *dev)
31 struct list_head *entry;
33 struct qfw_dev *qdev = dev_get_uclass_priv(dev);
35 /* don't read it twice */
36 if (!list_empty(&qdev->fw_list))
39 qfw_read_entry(dev, FW_CFG_FILE_DIR, 4, &count);
43 count = be32_to_cpu(count);
44 for (i = 0; i < count; i++) {
45 file = malloc(sizeof(*file));
47 printf("error: allocating resource\n");
50 qfw_read_entry(dev, FW_CFG_INVALID,
51 sizeof(struct fw_cfg_file), &file->cfg);
53 list_add_tail(&file->list, &qdev->fw_list);
59 list_for_each(entry, &qdev->fw_list) {
60 file = list_entry(entry, struct fw_file, list);
67 struct fw_file *qfw_find_file(struct udevice *dev, const char *name)
69 struct list_head *entry;
72 struct qfw_dev *qdev = dev_get_uclass_priv(dev);
74 list_for_each(entry, &qdev->fw_list) {
75 file = list_entry(entry, struct fw_file, list);
76 if (!strcmp(file->cfg.name, name))
83 struct fw_file *qfw_file_iter_init(struct udevice *dev,
84 struct fw_cfg_file_iter *iter)
86 struct qfw_dev *qdev = dev_get_uclass_priv(dev);
88 iter->entry = qdev->fw_list.next;
89 iter->end = &qdev->fw_list;
90 return list_entry((struct list_head *)iter->entry,
91 struct fw_file, list);
94 struct fw_file *qfw_file_iter_next(struct fw_cfg_file_iter *iter)
96 iter->entry = ((struct list_head *)iter->entry)->next;
97 return list_entry((struct list_head *)iter->entry,
98 struct fw_file, list);
101 bool qfw_file_iter_end(struct fw_cfg_file_iter *iter)
103 return iter->entry == iter->end;