1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2021 Linaro Limited
4 * Author: AKASHI Takahiro
8 #include <asm/global_data.h>
11 #include <linux/err.h>
12 #include <linux/list.h>
13 #include <linux/types.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 static const char *const tag_name[] = {
20 [DM_TAG_PLAT] = "plat",
21 [DM_TAG_PARENT_PLAT] = "parent_plat",
22 [DM_TAG_UC_PLAT] = "uclass_plat",
24 [DM_TAG_PRIV] = "priv",
25 [DM_TAG_PARENT_PRIV] = "parent_priv",
26 [DM_TAG_UC_PRIV] = "uclass_priv",
27 [DM_TAG_DRIVER_DATA] = "driver_data",
32 const char *tag_get_name(enum dm_tag_t tag)
37 int dev_tag_set_ptr(struct udevice *dev, enum dm_tag_t tag, void *ptr)
39 struct dmtag_node *node;
41 if (!dev || tag >= DM_TAG_COUNT)
44 list_for_each_entry(node, &gd->dmtag_list, sibling) {
45 if (node->dev == dev && node->tag == tag)
49 node = calloc(sizeof(*node), 1);
56 list_add_tail(&node->sibling, (struct list_head *)&gd->dmtag_list);
61 int dev_tag_set_val(struct udevice *dev, enum dm_tag_t tag, ulong val)
63 struct dmtag_node *node;
65 if (!dev || tag >= DM_TAG_COUNT)
68 list_for_each_entry(node, &gd->dmtag_list, sibling) {
69 if (node->dev == dev && node->tag == tag)
73 node = calloc(sizeof(*node), 1);
80 list_add_tail(&node->sibling, (struct list_head *)&gd->dmtag_list);
85 int dev_tag_get_ptr(struct udevice *dev, enum dm_tag_t tag, void **ptrp)
87 struct dmtag_node *node;
89 if (!dev || tag >= DM_TAG_COUNT)
92 list_for_each_entry(node, &gd->dmtag_list, sibling) {
93 if (node->dev == dev && node->tag == tag) {
102 int dev_tag_get_val(struct udevice *dev, enum dm_tag_t tag, ulong *valp)
104 struct dmtag_node *node;
106 if (!dev || tag >= DM_TAG_COUNT)
109 list_for_each_entry(node, &gd->dmtag_list, sibling) {
110 if (node->dev == dev && node->tag == tag) {
119 int dev_tag_del(struct udevice *dev, enum dm_tag_t tag)
121 struct dmtag_node *node, *tmp;
123 if (!dev || tag >= DM_TAG_COUNT)
126 list_for_each_entry_safe(node, tmp, &gd->dmtag_list, sibling) {
127 if (node->dev == dev && node->tag == tag) {
128 list_del(&node->sibling);
138 int dev_tag_del_all(struct udevice *dev)
140 struct dmtag_node *node, *tmp;
146 list_for_each_entry_safe(node, tmp, &gd->dmtag_list, sibling) {
147 if (node->dev == dev) {
148 list_del(&node->sibling);
160 void dev_tag_collect_stats(struct dm_stats *stats)
162 struct dmtag_node *node;
164 list_for_each_entry(node, &gd->dmtag_list, sibling) {
166 stats->tag_size += sizeof(struct dmtag_node);