From patchwork Fri Dec 10 06:49:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 522735 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp2170086imb; Thu, 9 Dec 2021 22:52:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvykooGWG1iTfCsBSzkkeQS/wKEZmbe2KmzJQRPZ1Is6YVCAQMlKk5rpvCtIcXa+GSJ4yk X-Received: by 2002:a17:907:c03:: with SMTP id ga3mr20489081ejc.180.1639119149448; Thu, 09 Dec 2021 22:52:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639119149; cv=none; d=google.com; s=arc-20160816; b=rPc0hsNJ6U0kdhXyOcdQZJzxtxGroKPKMktX6yH0FojcL1eIBfoZ7mKNXPCc5nGxds b4Q9yeDq9/NuTMMUXofWSCIVX9XRQxbAz7a2hSU5lZYzwAqHrYfNysrQr4Dkfkcd4R2i guI6T53vYEUHC9zVBFDWUcwtXCz1JUI6br/CPYr2rUJKW3DGEylqJgeUXl1iMgIqhcYB EuuxcNTxBqwoSev6csehoxsUXgbIeIwHC8PWimm3iMEp27jKxwwTzPiZNtgbrXK7oV1R 75Gj7kb+0Ipt/JwauK5m22lMVUz53k6dF/St+Y926Pzzccw0HLTViS+wi8F3HiJ5/fqK U3+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5ycV4eCQgzM+92pnWZI0t3c18bzKrR4QXUixcJeoN6s=; b=iDTTmE9zwCK/3YCA1Vl8u/kHRKwxMJa16StoFnOwoIjdb/nmVeGDSFG9A7umghIncr EHNsUzqOyrkhBwHW56UFwrZtY6hmUCEnsBUH1aX/L40zG9QIgIvLipZEB+hVSVcA+j7Q OLcF/Bd8+77MKa6TyMkBKaIXpwL2PVWqmCWs/2dgwdb4jn5IlyheiuhAsvNvHBLb0W05 Gp+MhQjoQNdGuW41RkaYTxt2q2zletKICFOXXrr48R+LLHjh86Pe8cwsRQlb+uCv6ouO jgR+1sKdjpp9JQwKZba0owRUQjP19yOy7/OWNaua5K7cz/QVUCiOM92ao9fcRTeRK/+d VXWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lsBZunZL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id y8si2525351ejw.78.2021.12.09.22.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:52:29 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lsBZunZL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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-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 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 */