From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AD41C433F5 for ; Fri, 10 Dec 2021 06:52:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 20BE78350D; Fri, 10 Dec 2021 07:51:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lsBZunZL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C536A82F03; Fri, 10 Dec 2021 07:51:11 +0100 (CET) Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A186183459 for ; Fri, 10 Dec 2021 07:50:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x632.google.com with SMTP id b11so5632763pld.12 for ; Thu, 09 Dec 2021 22:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5ycV4eCQgzM+92pnWZI0t3c18bzKrR4QXUixcJeoN6s=; b=lsBZunZLWwPiOmDE8n+WQfYOyQAy5xqRDZASdmCoUEv5ZziWNCRICOJOxF2/JA6G4F Xu7oiNQOV4ArdkDTJQMuyJdhJoV4+YxLiP652PK/nV85Am+8bqwbWlSmELYXMnLXa7qk uOY4BdA7duF5ro9z6QTXFBCJba+ET9Vk+bBbrBRhnhpcsR+q59ibTgF7182hGi/cblpo HjWtXk77IeyTzNn3y8F9qEKg2L8fW+PvAhIzqJwPRdciRrxuGvrE6z/e4GZKgfrqtgOw Tf6nBwX+X3cPGzkiQo7Xqpo9hMbdu7++MGtguCPRwk5EeHi/ot8VzL9b5MT+l2eyPCNN H3GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5ycV4eCQgzM+92pnWZI0t3c18bzKrR4QXUixcJeoN6s=; b=ymnrx0doBPN+aHkKNk/R333ilW8TtGGPyCLZ3kId//nLf5tmQ67mRmfBsmUsrrvY/v wBMh1N8pY8eDn5YWBm9Dq+0nIYvEX8+CzJ41bpiIqnY1ceVy/cpb9/AxS9KW8PfrP95L EqXlvsPjMDP5GHxD1HGDV1K6AAAI79KH/65VohnLPLuP7kj5awU0TSgnlbSac0fNXM/X VRfZ5kf1+Vd4zyAl3b8WXpV8sbZi6FCngeMH7jg2tklsS2Y9ZhMxGNZJ18TCHxNMY8WU WJcHkOa0d79h78UAP1WzafLmXkSvemOi0WmQV0w5iXkAhihaPsRnlsuGRC4VOqPt1rCw +Lzg== X-Gm-Message-State: AOAM530fP61f8vY1QHURky0jXt0QXO/tFsZHWOJpv9/OzEwfGcSmQHYx rDZgaqed2g5nY1V4BGfGt1EbrA== X-Google-Smtp-Source: ABdhPJxHX8AI7/k62Jwq5WZ/vH78i33gGfbPot8P7va6b5mhaqeHADP2yW0MPrHzVro3uj6JTEQP4A== X-Received: by 2002:a17:902:c404:b0:142:4c7e:ab8b with SMTP id k4-20020a170902c40400b001424c7eab8bmr73829040plk.10.1639119057035; Thu, 09 Dec 2021 22:50:57 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:75dd:4e0e:4542:936e]) by smtp.gmail.com with ESMTPSA id nn4sm1639035pjb.38.2021.12.09.22.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:50:56 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC v2 12/20] dm: add tag support Date: Fri, 10 Dec 2021 15:49:39 +0900 Message-Id: <20211210064947.73361-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210064947.73361-1-takahiro.akashi@linaro.org> References: <20211210064947.73361-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean With dm-tag feature, any U-Boot subsystem is allowed to associate arbitrary number of data with a particular udevice. This can been see as expanding "struct udevice" without modifying the definition. As a first user, UEFI subsystem makes use of tags to associate an efi_disk object with a block device. Signed-off-by: AKASHI Takahiro --- drivers/core/Makefile | 2 +- drivers/core/tag.c | 162 ++++++++++++++++++++++++++++++++++++++++++ include/dm/tag.h | 76 ++++++++++++++++++++ 3 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 drivers/core/tag.c create mode 100644 include/dm/tag.h diff --git a/drivers/core/Makefile b/drivers/core/Makefile index 5edd4e413576..3742e7574525 100644 --- a/drivers/core/Makefile +++ b/drivers/core/Makefile @@ -2,7 +2,7 @@ # # Copyright (c) 2013 Google, Inc -obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o +obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o tag.o obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o diff --git a/drivers/core/tag.c b/drivers/core/tag.c new file mode 100644 index 000000000000..562df3590c44 --- /dev/null +++ b/drivers/core/tag.c @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include + +struct udevice; + +static LIST_HEAD(dmtag_list); + +/** + * dev_tag_set_ptr() + * + */ +int dev_tag_set_ptr(struct udevice *dev, enum dm_tag_t tag, void *ptr) +{ + struct dmtag_node *node; + + if (!dev || tag > DM_TAG_COUNT) + return -EINVAL; + + list_for_each_entry(node, &dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) + return -EEXIST; + } + + node = calloc(sizeof(*node), 1); + if (!node) + return -ENOSPC; + + node->dev = dev; + node->tag = tag; + node->ptr = ptr; + list_add_tail(&node->sibling, &dmtag_list); + + return 0; +} + +/** + * dev_tag_set_val() + * + */ +int dev_tag_set_val(struct udevice *dev, enum dm_tag_t tag, ulong val) +{ + struct dmtag_node *node; + + if (!dev || tag > DM_TAG_COUNT) + return -EINVAL; + + list_for_each_entry(node, &dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) + return -EEXIST; + } + + node = calloc(sizeof(*node), 1); + if (!node) + return -ENOSPC; + + node->dev = dev; + node->tag = tag; + node->val = val; + list_add_tail(&node->sibling, &dmtag_list); + + return 0; +} + +/** + * dev_tag_get_ptr() + * + */ +int dev_tag_get_ptr(struct udevice *dev, enum dm_tag_t tag, void **ptrp) +{ + struct dmtag_node *node; + + if (!dev || tag > DM_TAG_COUNT) + return -EINVAL; + + list_for_each_entry(node, &dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) { + *ptrp = node->ptr; + return 0; + } + } + + return -ENOENT; +} + +/** + * dev_tag_get_val() + * + */ +int dev_tag_get_val(struct udevice *dev, enum dm_tag_t tag, ulong *valp) +{ + struct dmtag_node *node; + + if (!dev || tag > DM_TAG_COUNT) + return -EINVAL; + + list_for_each_entry(node, &dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) { + *valp = node->val; + return 0; + } + } + + return -ENOENT; +} + +/** + * dev_tag_del() + * + */ +int dev_tag_del(struct udevice *dev, enum dm_tag_t tag) +{ + struct dmtag_node *node, *tmp; + + if (!dev || tag > DM_TAG_COUNT) + return -EINVAL; + + list_for_each_entry_safe(node, tmp, &dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) { + list_del(&node->sibling); + free(node); + + return 0; + } + } + + return -ENOENT; +} + +/** + * dev_tag_del_all() + * + */ +int dev_tag_del_all(struct udevice *dev) +{ + struct dmtag_node *node, *tmp; + bool found = false; + + if (!dev) + return -EINVAL; + + list_for_each_entry_safe(node, tmp, &dmtag_list, sibling) { + if (node->dev == dev) { + list_del(&node->sibling); + free(node); + found = true; + } + } + + if (found) + return 0; + + return -ENOENT; +} diff --git a/include/dm/tag.h b/include/dm/tag.h new file mode 100644 index 000000000000..8f81b4f7ffaa --- /dev/null +++ b/include/dm/tag.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2021 Linaro Limited + * Author: AKASHI Takahiro + */ + +#ifndef _DM_TAG_H +#define _DM_TAG_H + +#include +#include + +struct udevice; + +enum dm_tag_t { + DM_TAG_EFI = 0, + + DM_TAG_COUNT, +}; + +/** + * dmtag_node + * + * @sibling: List of dm-tag nodes + * @dev: Associated udevice + * @tag: Tag type + * @ptr: Pointer as a value + * @val: Value + */ +struct dmtag_node { + struct list_head sibling; + struct udevice *dev; + enum dm_tag_t tag; + union { + void *ptr; + ulong val; + }; +}; + +/** + * dev_tag_set_ptr() + * + */ +int dev_tag_set_ptr(struct udevice *dev, enum dm_tag_t tag, void *ptr); + +/** + * dev_tag_set_val() + * + */ +int dev_tag_set_val(struct udevice *dev, enum dm_tag_t tag, ulong val); + +/** + * dev_tag_get_ptr() + * + */ +int dev_tag_get_ptr(struct udevice *dev, enum dm_tag_t tag, void **ptrp); + +/** + * dev_tag_get_val() + * + */ +int dev_tag_get_val(struct udevice *dev, enum dm_tag_t tag, ulong *valp); + +/** + * dev_tag_del() + * + */ +int dev_tag_del(struct udevice *dev, enum dm_tag_t tag); + +/** + * dev_tag_del_all() + * + */ +int dev_tag_del_all(struct udevice *dev); + +#endif /* _DM_TAG_H */ -- 2.33.0