From patchwork Sun Mar 27 20:26:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 554643 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp7677546mag; Sun, 27 Mar 2022 13:28:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAJKa+HYfTLFsp4bcKcGk09WKDagFLnM3I2RRNxiJs/ri2ZKg7AKNrm20dpobmcPz1jwIh X-Received: by 2002:a17:907:2d2a:b0:6df:c027:a3ac with SMTP id gs42-20020a1709072d2a00b006dfc027a3acmr23186075ejc.179.1648412922306; Sun, 27 Mar 2022 13:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648412922; cv=none; d=google.com; s=arc-20160816; b=bfTuMN9fFNG1ZJL8wKBWomre+cMfj5UZI9eSoHRNbdVJqMMH8Ni0GwBb4/tDOuBd3P YmGQe006pWhBllgLOObnd5YatEZOV5QqS8520YbWkFyA/dulZIz2coyXMtmcdSXh/XCv TQ5D4j8ZSxX61Pmb9/Z/2WoCvARRTUwfEjTv+p2vTffafgn2wdXnN3MNeeSAdK4vJyQ4 2mmClqpyieDZHa4adRqZWNL8vj/1gzIEHptn6fENe1zbRVabyA/C7iRVjMC4GSxpmEbR +GMxvzAxcTbWZBTg0WSjisZpPGrr9VvWZGVaZazSISXyG1nQ5IZKRgLQiTTwrM0pZY5Z Adjw== 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=yPp2bGhdeUFimOMHtTruSVnrWZkYmSmUP3HvTyAwjpA=; b=MagAujzp39/b8rEGTK377U9PYHtbmsLAFDZwgPBSRXKHEIod1qhBtWHmkHXNflL8Ls MbMJCI/QX11EnoE+Tu13UZzwkxUDrJ3MPpbtbsHftR/btV9nYXVWagViqAMoeeiJyaVI pILfuQt46F2RpOJycf+QPs/lIE55wBcbczP7La0Rc3TBjXjL7cVRqnHLpsoScJo/dlHO 8rOn2sSK4HTQ5u1lI6v6bRC7Di5e3FZv6JowHz04/79pmwfQ6deGKZW1dK3RK15MUrr5 6IuT6Sa4XSWU419zGBRT1OZMt/Vzf2DnouzZx521VsaRFsYrNBQkDobGZ9pRBbqh+cZK 5Q5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="i/2GapDf"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id i16-20020a17090685d000b006df76385d5bsi9643138ejy.507.2022.03.27.13.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 13:28:42 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="i/2GapDf"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D738383AC2; Sun, 27 Mar 2022 22:27:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="i/2GapDf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B0183839FD; Sun, 27 Mar 2022 22:27:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 D1131839C7 for ; Sun, 27 Mar 2022 22:27:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-pg1-x530.google.com with SMTP id t13so9451384pgn.8 for ; Sun, 27 Mar 2022 13:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yPp2bGhdeUFimOMHtTruSVnrWZkYmSmUP3HvTyAwjpA=; b=i/2GapDfgJuNx8cSEgVf5YUdKzNUleqLgZJQSmTc07FCcK3e/FpdO1II/61mpMBzDc ygTeCa9NP4Z3cFWRwPcnm8JHLIFFDT4M88Ac4Wb3KT4f3193kNkJyPTVWJBri5atfZQY q2jgRpo78rbmoammQySPC2d3auoHqKyPIGm5o= 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=yPp2bGhdeUFimOMHtTruSVnrWZkYmSmUP3HvTyAwjpA=; b=pkZGPWG7cFNZeRU+dLZeCBiwxrrEu7VCWOLh4FG1fpd2+4SIBMfbl5mWNcHXgN8zE0 4hJB9ZChy0nNwcSPybRasnHskmex/Ij6UfXbeukPtXAYRvsQ5vLi3qUIlkqADjq/Pe3R t30Ahtixh8D6BOzr+NxT1h9dh0/Apvxp3YTdqy2dBj0JtHCIJlP4OzG9KAhZx2km6yk+ PGEvAUHkmFNNclTy0pWcf2XphvcQ2KWgEFCI85ztYB6pehLYMJjIr1il6zZ3m7jz6IHw osNzwMLbiePs43go1srDHA9vkFrvpQ3SFGBZFEMnQnwQj9N4Lvos5OmIYtBeOJeGt4DD Cu2A== X-Gm-Message-State: AOAM533pYl03PyglFkUvkcZBY2Uh+UwP/CVEE/m0xk+p2eN6xh5QCeU9 gmmaidg9wUQFRIn5ePsFgpfQR7/KWM6nHw== X-Received: by 2002:a65:4b84:0:b0:382:65ea:bb10 with SMTP id t4-20020a654b84000000b0038265eabb10mr7732532pgq.50.1648412843132; Sun, 27 Mar 2022 13:27:23 -0700 (PDT) Received: from localhost.localdomain (118-93-105-181.dsl.dyn.ihug.co.nz. [118.93.105.181]) by smtp.gmail.com with ESMTPSA id k3-20020a056a00168300b004f7e60da26csm13915466pfc.182.2022.03.27.13.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 13:27:22 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Sean Anderson , =?utf-8?q?Marek_Beh=C3=BAn?= , U-Boot Custodians , Tom Rini , AKASHI Takahiro , Simon Glass , Bin Meng , Dario Binacchi , Marek Vasut , Pavel Herrmann , Rasmus Villemoes Subject: [PATCH 09/10] RFC: dm: add tag support Date: Sun, 27 Mar 2022 14:26:21 -0600 Message-Id: <20220327202622.3438333-8-sjg@chromium.org> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog In-Reply-To: <20220327202622.3438333-1-sjg@chromium.org> References: <20220327202622.3438333-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean From: AKASHI Takahiro Note: This patch is *still* pending, so it is included in this series just to make it work. 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 Reviewed-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/Makefile | 2 +- drivers/core/root.c | 2 + drivers/core/tag.c | 139 ++++++++++++++++++++++++++++++ include/asm-generic/global_data.h | 4 + include/dm/tag.h | 110 +++++++++++++++++++++++ 5 files changed, 256 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 0cbc3ab217e..7099073a533 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_$(SPL_TPL_)DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o diff --git a/drivers/core/root.c b/drivers/core/root.c index 6d1a4097e14..e09c12f4d6e 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -205,6 +205,8 @@ int dm_init(bool of_live) return ret; } + INIT_LIST_HEAD((struct list_head *)&gd->dmtag_list); + return 0; } diff --git a/drivers/core/tag.c b/drivers/core/tag.c new file mode 100644 index 00000000000..6829bcd8806 --- /dev/null +++ b/drivers/core/tag.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include + +struct udevice; + +DECLARE_GLOBAL_DATA_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, &gd->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, (struct list_head *)&gd->dmtag_list); + + return 0; +} + +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, &gd->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, (struct list_head *)&gd->dmtag_list); + + return 0; +} + +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, &gd->dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) { + *ptrp = node->ptr; + return 0; + } + } + + return -ENOENT; +} + +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, &gd->dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) { + *valp = node->val; + return 0; + } + } + + return -ENOENT; +} + +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, &gd->dmtag_list, sibling) { + if (node->dev == dev && node->tag == tag) { + list_del(&node->sibling); + free(node); + + return 0; + } + } + + return -ENOENT; +} + +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, &gd->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/asm-generic/global_data.h b/include/asm-generic/global_data.h index e49f5bf2f7d..59bd6804368 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -474,6 +474,10 @@ struct global_data { */ struct event_state event_state; #endif + /** + * @dmtag_list: List of DM tags + */ + struct list_head dmtag_list; }; #ifndef DO_DEPS_ONLY static_assert(sizeof(struct global_data) == GD_SIZE); diff --git a/include/dm/tag.h b/include/dm/tag.h new file mode 100644 index 00000000000..54fc31eb153 --- /dev/null +++ b/include/dm/tag.h @@ -0,0 +1,110 @@ +/* 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 { + /* EFI_LOADER */ + 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() - set a tag's value as a pointer + * @dev: Device to operate + * @tag: Tag type + * @ptr: Pointer to set + * + * Set the value, @ptr, as of @tag associated with the device, @dev + * + * Return: 0 on success, -ve on error + */ +int dev_tag_set_ptr(struct udevice *dev, enum dm_tag_t tag, void *ptr); + +/** + * dev_tag_set_val() set a tag's value as an integer + * @dev: Device to operate + * @tag: Tag type + * @val: Value to set + * + * Set the value, @val, as of @tag associated with the device, @dev + * + * Return: on success, -ve on error + */ +int dev_tag_set_val(struct udevice *dev, enum dm_tag_t tag, ulong val); + +/** + * dev_tag_get_ptr() - get a tag's value as a pointer + * @dev: Device to operate + * @tag: Tag type + * @ptrp: Pointer to tag's value (pointer) + * + * Get a tag's value as a pointer + * + * Return: on success, -ve on error + */ +int dev_tag_get_ptr(struct udevice *dev, enum dm_tag_t tag, void **ptrp); + +/** + * dev_tag_get_val() - get a tag's value as an integer + * @dev: Device to operate + * @tag: Tag type + * @valp: Pointer to tag's value (ulong) + * + * Get a tag's value as an integer + * + * Return: 0 on success, -ve on error + */ +int dev_tag_get_val(struct udevice *dev, enum dm_tag_t tag, ulong *valp); + +/** + * dev_tag_del() - delete a tag + * @dev: Device to operate + * @tag: Tag type + * + * Delete a tag of @tag associated with the device, @dev + * + * Return: 0 on success, -ve on error + */ +int dev_tag_del(struct udevice *dev, enum dm_tag_t tag); + +/** + * dev_tag_del_all() - delete all tags + * @dev: Device to operate + * + * Delete all the tags associated with the device, @dev + * + * Return: 0 on success, -ve on error + */ +int dev_tag_del_all(struct udevice *dev); + +#endif /* _DM_TAG_H */