From patchwork Mon Jan 27 15:49:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229901 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=fIkNeZWZ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vN44S6nz9sPJ for ; Tue, 28 Jan 2020 02:50:25 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 30ECD81A1C; Mon, 27 Jan 2020 16:50:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="fIkNeZWZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4077481A19; Mon, 27 Jan 2020 16:50:16 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 5E87081A0B for ; Mon, 27 Jan 2020 16:50:11 +0100 (CET) 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-io1-xd42.google.com with SMTP id c16so10510043ioh.6 for ; Mon, 27 Jan 2020 07:50:11 -0800 (PST) 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=WG9P6n++56vvUP7IqnA8pj+vOHnDUcV+eYGO1yno3JQ=; b=fIkNeZWZE5ZM8jbOM2pUt4S2pk/2uuRT+e2tGi/eALBtUxj6g3mZkzvthqmr5VVcC1 kMAkovtKi+UYlz4vf6j7BRgL16Gb+Yghd/eZKIDVxJLuBxqAChia90Y1BGIkovwKCWPi x1lIpGewo5vV3v2CKyyLOsIqRqvbxTl8POLVo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WG9P6n++56vvUP7IqnA8pj+vOHnDUcV+eYGO1yno3JQ=; b=Nua/ZuKy5E3SViT2fg6EpDMx9bwvpzNV2QQDb5EX4EREjo2m9PPqMG2CLuttbWD37i DTCniwDn1Jfe3cWzAppLQyLDhYwOx2yQsFuBmPi4OD1RqUw+ZDyjjdXcPul7w0BdAqJq 546XsoeNQgYO1NVTPYpHl13ycOpvw5TPGwXseh1QJ/w03HtDkBIZIBZ4gYHMRw6jBq4T wUvuIKmq0Xhlwu5dAs0AnWIQscbbMYbAoZ/X7tEK+LSEzLH7FGTdV2n0xFF3VGIzJP1q jH7tom6cMIQyUL7uK4FJs/fh+ccWs6ZEbYhBhLGHXM0NrJI4w56GRJsPX1B9jAkhyGh0 GtcQ== X-Gm-Message-State: APjAAAViHhi53juttR70M+2sCH1S0g6rFbf8Z6mUKedoAmdHyoI/Hafp P7IteoF/XxT4hikd4fEG/6xp2vbRwhc= X-Google-Smtp-Source: APXvYqySMh7egYxsaCw01Z5gxBHJFPCF1PixD44OFhDVjc+5gdSUFOCl+AFW5R5XzNo6Kl2hvSKDQA== X-Received: by 2002:a6b:db12:: with SMTP id t18mr12173677ioc.11.1580140209435; Mon, 27 Jan 2020 07:50:09 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:09 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 01/21] dm: core: Use const where possible in device.h Date: Mon, 27 Jan 2020 08:49:36 -0700 Message-Id: <20200127084920.1.Iafefa95a02355a5e67f9638d115e4a038c8f791d@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Update this header file to use const devices where possible, to permit callers to also use const. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/device.c | 27 ++++++++++++++------------- include/dm/device.h | 30 ++++++++++++++++-------------- include/dm/read.h | 4 ++-- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 9f39218423..b7f59fcde3 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -591,7 +591,8 @@ static int device_find_by_ofnode(ofnode node, struct udevice **devp) } #endif -int device_get_child(struct udevice *parent, int index, struct udevice **devp) +int device_get_child(const struct udevice *parent, int index, + struct udevice **devp) { struct udevice *dev; @@ -603,7 +604,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp) return -ENODEV; } -int device_get_child_count(struct udevice *parent) +int device_get_child_count(const struct udevice *parent) { struct udevice *dev; int count = 0; @@ -614,7 +615,7 @@ int device_get_child_count(struct udevice *parent) return count; } -int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, +int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { struct udevice *dev; @@ -634,7 +635,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, return -ENODEV; } -int device_get_child_by_seq(struct udevice *parent, int seq, +int device_get_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp) { struct udevice *dev; @@ -652,7 +653,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq, return device_get_device_tail(dev, ret, devp); } -int device_find_child_by_of_offset(struct udevice *parent, int of_offset, +int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp) { struct udevice *dev; @@ -669,7 +670,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset, return -ENODEV; } -int device_get_child_by_of_offset(struct udevice *parent, int node, +int device_get_child_by_of_offset(const struct udevice *parent, int node, struct udevice **devp) { struct udevice *dev; @@ -712,7 +713,7 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp) return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); } -int device_find_first_child(struct udevice *parent, struct udevice **devp) +int device_find_first_child(const struct udevice *parent, struct udevice **devp) { if (list_empty(&parent->child_head)) { *devp = NULL; @@ -739,7 +740,7 @@ int device_find_next_child(struct udevice **devp) return 0; } -int device_find_first_inactive_child(struct udevice *parent, +int device_find_first_inactive_child(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp) { @@ -757,7 +758,7 @@ int device_find_first_inactive_child(struct udevice *parent, return -ENODEV; } -int device_find_first_child_by_uclass(struct udevice *parent, +int device_find_first_child_by_uclass(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp) { @@ -774,7 +775,7 @@ int device_find_first_child_by_uclass(struct udevice *parent, return -ENODEV; } -int device_find_child_by_name(struct udevice *parent, const char *name, +int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp) { struct udevice *dev; @@ -827,7 +828,7 @@ bool device_has_children(const struct udevice *dev) return !list_empty(&dev->child_head); } -bool device_has_active_children(struct udevice *dev) +bool device_has_active_children(const struct udevice *dev) { struct udevice *child; @@ -841,7 +842,7 @@ bool device_has_active_children(struct udevice *dev) return false; } -bool device_is_last_sibling(struct udevice *dev) +bool device_is_last_sibling(const struct udevice *dev) { struct udevice *parent = dev->parent; @@ -867,7 +868,7 @@ int device_set_name(struct udevice *dev, const char *name) } #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) -bool device_is_compatible(struct udevice *dev, const char *compat) +bool device_is_compatible(const struct udevice *dev, const char *compat) { return ofnode_device_is_compatible(dev_ofnode(dev), compat); } diff --git a/include/dm/device.h b/include/dm/device.h index 1138a09149..611fc2e197 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -409,7 +409,8 @@ const char *dev_get_uclass_name(const struct udevice *dev); * @return 0 if OK, -ENODEV if no such device, other error if the device fails * to probe */ -int device_get_child(struct udevice *parent, int index, struct udevice **devp); +int device_get_child(const struct udevice *parent, int index, + struct udevice **devp); /** * device_get_child_count() - Get the available child count of a device @@ -418,7 +419,7 @@ int device_get_child(struct udevice *parent, int index, struct udevice **devp); * * @parent: Parent device to check */ -int device_get_child_count(struct udevice *parent); +int device_get_child_count(const struct udevice *parent); /** * device_find_child_by_seq() - Find a child device based on a sequence @@ -439,7 +440,7 @@ int device_get_child_count(struct udevice *parent); * Set to NULL if none is found * @return 0 if OK, -ve on error */ -int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, +int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp); /** @@ -457,7 +458,7 @@ int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, * Set to NULL if none is found * @return 0 if OK, -ve on error */ -int device_get_child_by_seq(struct udevice *parent, int seq, +int device_get_child_by_seq(const struct udevice *parent, int seq, struct udevice **devp); /** @@ -470,7 +471,7 @@ int device_get_child_by_seq(struct udevice *parent, int seq, * @devp: Returns pointer to device if found, otherwise this is set to NULL * @return 0 if OK, -ve on error */ -int device_find_child_by_of_offset(struct udevice *parent, int of_offset, +int device_find_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp); /** @@ -485,7 +486,7 @@ int device_find_child_by_of_offset(struct udevice *parent, int of_offset, * @devp: Returns pointer to device if found, otherwise this is set to NULL * @return 0 if OK, -ve on error */ -int device_get_child_by_of_offset(struct udevice *parent, int of_offset, +int device_get_child_by_of_offset(const struct udevice *parent, int of_offset, struct udevice **devp); /** @@ -524,7 +525,8 @@ int device_get_global_by_ofnode(ofnode node, struct udevice **devp); * @devp: Returns first child device, or NULL if none * @return 0 */ -int device_find_first_child(struct udevice *parent, struct udevice **devp); +int device_find_first_child(const struct udevice *parent, + struct udevice **devp); /** * device_find_next_child() - Find the next child of a device @@ -548,7 +550,7 @@ int device_find_next_child(struct udevice **devp); * @devp: Returns device found, if any * @return 0 if found, else -ENODEV */ -int device_find_first_inactive_child(struct udevice *parent, +int device_find_first_inactive_child(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp); @@ -560,7 +562,7 @@ int device_find_first_inactive_child(struct udevice *parent, * @devp: Returns first child device in that uclass, if any * @return 0 if found, else -ENODEV */ -int device_find_first_child_by_uclass(struct udevice *parent, +int device_find_first_child_by_uclass(const struct udevice *parent, enum uclass_id uclass_id, struct udevice **devp); @@ -572,7 +574,7 @@ int device_find_first_child_by_uclass(struct udevice *parent, * @devp: Returns device found, if any * @return 0 if found, else -ENODEV */ -int device_find_child_by_name(struct udevice *parent, const char *name, +int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp); /** @@ -590,7 +592,7 @@ bool device_has_children(const struct udevice *dev); * @return true if the device has one or more children and at least one of * them is active (probed). */ -bool device_has_active_children(struct udevice *dev); +bool device_has_active_children(const struct udevice *dev); /** * device_is_last_sibling() - check if a device is the last sibling @@ -603,7 +605,7 @@ bool device_has_active_children(struct udevice *dev); * @return true if there are no more siblings after this one - i.e. is it * last in the list. */ -bool device_is_last_sibling(struct udevice *dev); +bool device_is_last_sibling(const struct udevice *dev); /** * device_set_name() - set the name of a device @@ -643,7 +645,7 @@ void device_set_name_alloced(struct udevice *dev); * device * @return true if OK, false if the compatible is not found */ -bool device_is_compatible(struct udevice *dev, const char *compat); +bool device_is_compatible(const struct udevice *dev, const char *compat); /** * of_machine_is_compatible() - check if the machine is compatible with @@ -678,7 +680,7 @@ int dev_enable_by_path(const char *path); * @dev: device to test * @return: true if it is on a PCI bus, false otherwise */ -static inline bool device_is_on_pci_bus(struct udevice *dev) +static inline bool device_is_on_pci_bus(const struct udevice *dev) { return device_get_uclass_id(dev->parent) == UCLASS_PCI; } diff --git a/include/dm/read.h b/include/dm/read.h index d37fcb504d..f1c1553f80 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -33,12 +33,12 @@ static inline const struct device_node *dev_np(struct udevice *dev) * @dev: device to check * @return reference of the the device's DT node */ -static inline ofnode dev_ofnode(struct udevice *dev) +static inline ofnode dev_ofnode(const struct udevice *dev) { return dev->node; } -static inline bool dev_of_valid(struct udevice *dev) +static inline bool dev_of_valid(const struct udevice *dev) { return ofnode_valid(dev_ofnode(dev)); } From patchwork Mon Jan 27 15:49:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229903 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=icDRYown; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vNN4DH8z9sRW for ; Tue, 28 Jan 2020 02:50:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41A2B81A22; Mon, 27 Jan 2020 16:50:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="icDRYown"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 645C881A1E; Mon, 27 Jan 2020 16:50:18 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 A165481A12 for ; Mon, 27 Jan 2020 16:50:12 +0100 (CET) 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-io1-xd42.google.com with SMTP id i11so10478478ioi.12 for ; Mon, 27 Jan 2020 07:50:12 -0800 (PST) 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=CUvQvlEf5MafAXdjExXgjZqrxF0VZIecZHm7E9cq4sg=; b=icDRYownc7H4P46D+P4C6fnT9Fe3uBUrCoJgQAqp6xEtqJNC8tL79OJaBT4j+DGJpM Vv/sHHFbFpAhBo3E7+FpcLL7g5jFauuQ7yGBspuTQkWoVaug04T08RUyx2DU/TYjbZUA HnxYAOQTqn34zbsqeLgreL6Se3rIQXpHtHQzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CUvQvlEf5MafAXdjExXgjZqrxF0VZIecZHm7E9cq4sg=; b=A/dqb/1SrUQnPgtZVkAG/Ckftt9zl2Fc4rIxDHX90Eeq4gQpaIxU0bwnCF4KvfMbUV eke6FavGyOcFt1LqqCQUTuP7ORbcfnCL7hY7+KZ1EBTh6f5S7E2Qz5r3fQnDP4EWEaJI wrG0jsw/rj/rT71ji8Hs3qgpp+eX779EJbetDk6sxiq6Reao0jkAl44ifGwCmpc0MYFJ A4ojgNnhOrsS5BKefoaIkDR4erV+sO8FUfQvR8vVXETYO1NeUfloJzLWrMFk0TkFO+N1 fn0Yeu4YAzkPqZuAWiWVnIQx/2V5n7pH4evM88oPZTY9pUCUaLvsJFtd/hL+NCWB3hWF KnSg== X-Gm-Message-State: APjAAAUSJ1YRFqsW7kFiZjx9nc24RMwx4xWnSRzTtbwuMFtYIE+JZ6Kx MhynJ1egJ/1WVsULHWAl2OoAhI7QOew= X-Google-Smtp-Source: APXvYqxhV1uS1XRyzHe1abDi/yTCrp1jx8pux/Rm5kG21/DLTBajArRF2SQFGzOz9DE5yW2Yk8cvSw== X-Received: by 2002:a5e:8214:: with SMTP id l20mr13501148iom.168.1580140210659; Mon, 27 Jan 2020 07:50:10 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:10 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 02/21] dm: pci: Update the PCI read_config() method to const dev * Date: Mon, 27 Jan 2020 08:49:37 -0700 Message-Id: <20200127084920.2.I900b0334ac3e2377865fef23204521c1ac59410d@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann , Stefan Roese , Marek Vasut , Ryder Lee , Ramon Fried , liuhao , Hou Zhiqiang , Thierry Reding , shuyiqi , Bao Xiaowei , Prabhakar Kushwaha , GSS_MTK_Uboot_upstream Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean At present this method uses a non-const udevice pointer, but the call should not modify the device. Use a const pointer. Signed-off-by: Simon Glass Reviewed-by: Ley Foon Tan Reviewed-by: Ley Foon Tan --- drivers/misc/p2sb_emul.c | 5 +++-- drivers/misc/swap_case.c | 9 +++++---- drivers/pci/pci-aardvark.c | 2 +- drivers/pci/pci-emul-uclass.c | 2 +- drivers/pci/pci-rcar-gen2.c | 4 ++-- drivers/pci/pci-rcar-gen3.c | 2 +- drivers/pci/pci-uclass.c | 14 ++++++++------ drivers/pci/pci_mpc85xx.c | 2 +- drivers/pci/pci_mvebu.c | 2 +- drivers/pci/pci_sandbox.c | 2 +- drivers/pci/pci_sh7751.c | 2 +- drivers/pci/pci_tegra.c | 2 +- drivers/pci/pci_x86.c | 5 +++-- drivers/pci/pcie_dw_mvebu.c | 2 +- drivers/pci/pcie_dw_ti.c | 2 +- drivers/pci/pcie_ecam_generic.c | 11 ++++++----- drivers/pci/pcie_fsl.c | 2 +- drivers/pci/pcie_imx.c | 2 +- drivers/pci/pcie_intel_fpga.c | 4 ++-- drivers/pci/pcie_layerscape.c | 4 ++-- drivers/pci/pcie_layerscape_gen4.c | 2 +- drivers/pci/pcie_mediatek.c | 4 ++-- drivers/pci/pcie_phytium.c | 7 +++---- drivers/pci/pcie_xilinx.c | 4 ++-- drivers/power/acpi_pmc/pmc_emul.c | 2 +- include/pci.h | 22 ++++++++++++---------- 26 files changed, 64 insertions(+), 57 deletions(-) diff --git a/drivers/misc/p2sb_emul.c b/drivers/misc/p2sb_emul.c index c3795c59c0..a6ee9a235e 100644 --- a/drivers/misc/p2sb_emul.c +++ b/drivers/misc/p2sb_emul.c @@ -48,8 +48,9 @@ struct p2sb_emul_priv { u8 regs[16]; }; -static int sandbox_p2sb_emul_read_config(struct udevice *emul, uint offset, - ulong *valuep, enum pci_size_t size) +static int sandbox_p2sb_emul_read_config(const struct udevice *emul, + uint offset, ulong *valuep, + enum pci_size_t size) { struct p2sb_emul_platdata *plat = dev_get_platdata(emul); diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c index 11189d16c8..97e2afa676 100644 --- a/drivers/misc/swap_case.c +++ b/drivers/misc/swap_case.c @@ -51,7 +51,7 @@ struct swap_case_priv { char mem_text[MEM_TEXT_SIZE]; }; -static int sandbox_swap_case_use_ea(struct udevice *dev) +static int sandbox_swap_case_use_ea(const struct udevice *dev) { return !!ofnode_get_property(dev->node, "use-ea", NULL); } @@ -82,7 +82,7 @@ static const u32 ea_regs[] = { PCI_CAP_EA_SIZE_HI, }; -static int sandbox_swap_case_read_ea(struct udevice *emul, uint offset, +static int sandbox_swap_case_read_ea(const struct udevice *emul, uint offset, ulong *valuep, enum pci_size_t size) { u32 reg; @@ -95,8 +95,9 @@ static int sandbox_swap_case_read_ea(struct udevice *emul, uint offset, return 0; } -static int sandbox_swap_case_read_config(struct udevice *emul, uint offset, - ulong *valuep, enum pci_size_t size) +static int sandbox_swap_case_read_config(const struct udevice *emul, + uint offset, ulong *valuep, + enum pci_size_t size) { struct swap_case_platdata *plat = dev_get_platdata(emul); diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c index aa0b4bc845..f1527ac667 100644 --- a/drivers/pci/pci-aardvark.c +++ b/drivers/pci/pci-aardvark.c @@ -297,7 +297,7 @@ static int pcie_advk_check_pio_status(struct pcie_advk *pcie, * * Return: 0 on success */ -static int pcie_advk_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c index 0f63e491a7..9486e1cb96 100644 --- a/drivers/pci/pci-emul-uclass.c +++ b/drivers/pci/pci-emul-uclass.c @@ -15,7 +15,7 @@ struct sandbox_pci_emul_priv { int dev_count; }; -int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, +int sandbox_pci_get_emul(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **containerp, struct udevice **emulp) { struct pci_emul_uc_priv *upriv; diff --git a/drivers/pci/pci-rcar-gen2.c b/drivers/pci/pci-rcar-gen2.c index d913d53f3c..014d870478 100644 --- a/drivers/pci/pci-rcar-gen2.c +++ b/drivers/pci/pci-rcar-gen2.c @@ -107,7 +107,7 @@ static int rcar_gen2_pci_addr_valid(pci_dev_t d, uint offset) return 0; } -static u32 get_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) +static u32 get_bus_address(const struct udevice *dev, pci_dev_t bdf, u32 offset) { struct rcar_gen2_pci_priv *priv = dev_get_priv(dev); @@ -126,7 +126,7 @@ static u32 setup_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) return get_bus_address(dev, bdf, offset); } -static int rcar_gen2_pci_read_config(struct udevice *dev, pci_dev_t bdf, +static int rcar_gen2_pci_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pci-rcar-gen3.c b/drivers/pci/pci-rcar-gen3.c index 52ca13b70c..4ea7930613 100644 --- a/drivers/pci/pci-rcar-gen3.c +++ b/drivers/pci/pci-rcar-gen3.c @@ -204,7 +204,7 @@ static int rcar_gen3_pcie_addr_valid(pci_dev_t d, uint where) return 0; } -static int rcar_gen3_pcie_read_config(struct udevice *dev, pci_dev_t bdf, +static int rcar_gen3_pcie_read_config(const struct udevice *dev, pci_dev_t bdf, uint where, ulong *val, enum pci_size_t size) { diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 5be2dfd0bf..78d4129572 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -124,7 +124,7 @@ static void pci_dev_find_ofnode(struct udevice *bus, phys_addr_t bdf, } }; -int pci_bus_find_devfn(struct udevice *bus, pci_dev_t find_devfn, +int pci_bus_find_devfn(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **devp) { struct udevice *dev; @@ -551,8 +551,9 @@ int pci_auto_config_devices(struct udevice *bus) } int pci_generic_mmap_write_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong value, @@ -579,8 +580,9 @@ int pci_generic_mmap_write_config( } int pci_generic_mmap_read_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong *valuep, @@ -1054,7 +1056,7 @@ static int pci_uclass_child_post_bind(struct udevice *dev) return 0; } -static int pci_bridge_read_config(struct udevice *bus, pci_dev_t bdf, +static int pci_bridge_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_mpc85xx.c b/drivers/pci/pci_mpc85xx.c index e58ab60ee0..8dff68dbd0 100644 --- a/drivers/pci/pci_mpc85xx.c +++ b/drivers/pci/pci_mpc85xx.c @@ -15,7 +15,7 @@ struct mpc85xx_pci_priv { void __iomem *cfg_data; }; -static int mpc85xx_pci_dm_read_config(struct udevice *dev, pci_dev_t bdf, +static int mpc85xx_pci_dm_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pci_mvebu.c b/drivers/pci/pci_mvebu.c index f9b08f38a1..7d9ad34e9d 100644 --- a/drivers/pci/pci_mvebu.c +++ b/drivers/pci/pci_mvebu.c @@ -136,7 +136,7 @@ static inline struct mvebu_pcie *hose_to_pcie(struct pci_controller *hose) return container_of(hose, struct mvebu_pcie, hose); } -static int mvebu_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int mvebu_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_sandbox.c b/drivers/pci/pci_sandbox.c index 2af2b79c05..fa4c476597 100644 --- a/drivers/pci/pci_sandbox.c +++ b/drivers/pci/pci_sandbox.c @@ -39,7 +39,7 @@ static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn, return ops->write_config(emul, offset, value, size); } -static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn, +static int sandbox_pci_read_config(const struct udevice *bus, pci_dev_t devfn, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_sh7751.c b/drivers/pci/pci_sh7751.c index 53e1668c99..b39c6283db 100644 --- a/drivers/pci/pci_sh7751.c +++ b/drivers/pci/pci_sh7751.c @@ -85,7 +85,7 @@ static u32 get_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) return BIT(31) | (PCI_DEV(bdf) << 8) | (offset & ~3); } -static int sh7751_pci_read_config(struct udevice *dev, pci_dev_t bdf, +static int sh7751_pci_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pci_tegra.c b/drivers/pci/pci_tegra.c index 56c08585e6..96d308f7bf 100644 --- a/drivers/pci/pci_tegra.c +++ b/drivers/pci/pci_tegra.c @@ -308,7 +308,7 @@ static int tegra_pcie_conf_address(struct tegra_pcie *pcie, pci_dev_t bdf, } } -static int pci_tegra_read_config(struct udevice *bus, pci_dev_t bdf, +static int pci_tegra_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pci_x86.c b/drivers/pci/pci_x86.c index e76a9c6e44..8d036930e7 100644 --- a/drivers/pci/pci_x86.c +++ b/drivers/pci/pci_x86.c @@ -8,8 +8,9 @@ #include #include -static int _pci_x86_read_config(struct udevice *bus, pci_dev_t bdf, uint offset, - ulong *valuep, enum pci_size_t size) +static int _pci_x86_read_config(const struct udevice *bus, pci_dev_t bdf, + uint offset, ulong *valuep, + enum pci_size_t size) { return pci_x86_read_config(bdf, offset, valuep, size); } diff --git a/drivers/pci/pcie_dw_mvebu.c b/drivers/pci/pcie_dw_mvebu.c index 693591e375..1f216e1c68 100644 --- a/drivers/pci/pcie_dw_mvebu.c +++ b/drivers/pci/pcie_dw_mvebu.c @@ -240,7 +240,7 @@ static int pcie_dw_addr_valid(pci_dev_t d, int first_busno) * * Return: 0 on success */ -static int pcie_dw_mvebu_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_dw_mvebu_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_dw_ti.c b/drivers/pci/pcie_dw_ti.c index b37fc2de7f..433640d3e7 100644 --- a/drivers/pci/pcie_dw_ti.c +++ b/drivers/pci/pcie_dw_ti.c @@ -289,7 +289,7 @@ static int pcie_dw_addr_valid(pci_dev_t d, int first_busno) * * Return: 0 on success */ -static int pcie_dw_ti_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_dw_ti_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_ecam_generic.c b/drivers/pci/pcie_ecam_generic.c index 00644edd26..c875f3a5b7 100644 --- a/drivers/pci/pcie_ecam_generic.c +++ b/drivers/pci/pcie_ecam_generic.c @@ -35,8 +35,9 @@ struct generic_ecam_pcie { * code. Otherwise the address to access will be written to the pointer pointed * to by @paddress. */ -static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf, - uint offset, void **paddress) +static int pci_generic_ecam_conf_address(const struct udevice *bus, + pci_dev_t bdf, uint offset, + void **paddress) { struct generic_ecam_pcie *pcie = dev_get_priv(bus); void *addr; @@ -63,9 +64,9 @@ static int pci_generic_ecam_conf_address(struct udevice *bus, pci_dev_t bdf, * space of the device identified by the bus, device & function numbers in @bdf * on the PCI bus @bus. */ -static int pci_generic_ecam_read_config(struct udevice *bus, pci_dev_t bdf, - uint offset, ulong *valuep, - enum pci_size_t size) +static int pci_generic_ecam_read_config(const struct udevice *bus, + pci_dev_t bdf, uint offset, + ulong *valuep, enum pci_size_t size) { return pci_generic_mmap_read_config(bus, pci_generic_ecam_conf_address, bdf, offset, valuep, size); diff --git a/drivers/pci/pcie_fsl.c b/drivers/pci/pcie_fsl.c index ab25aeee73..f516ec0576 100644 --- a/drivers/pci/pcie_fsl.c +++ b/drivers/pci/pcie_fsl.c @@ -42,7 +42,7 @@ static int fsl_pcie_addr_valid(struct fsl_pcie *pcie, pci_dev_t bdf) return 0; } -static int fsl_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int fsl_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_imx.c b/drivers/pci/pcie_imx.c index 3621636cb2..8e1713a2d1 100644 --- a/drivers/pci/pcie_imx.c +++ b/drivers/pci/pcie_imx.c @@ -748,7 +748,7 @@ void pci_init_board(void) imx_pcie_init(); } #else -static int imx_pcie_dm_read_config(struct udevice *dev, pci_dev_t bdf, +static int imx_pcie_dm_read_config(const struct udevice *dev, pci_dev_t bdf, uint offset, ulong *value, enum pci_size_t size) { diff --git a/drivers/pci/pcie_intel_fpga.c b/drivers/pci/pcie_intel_fpga.c index a5ea4888f3..a1f6e95e69 100644 --- a/drivers/pci/pcie_intel_fpga.c +++ b/drivers/pci/pcie_intel_fpga.c @@ -226,7 +226,7 @@ static int tlp_cfg_dword_write(struct intel_fpga_pcie *pcie, pci_dev_t bdf, return tlp_read_packet(pcie, NULL); } -int intel_fpga_rp_conf_addr(struct udevice *bus, pci_dev_t bdf, +int intel_fpga_rp_conf_addr(const struct udevice *bus, pci_dev_t bdf, uint offset, void **paddress) { struct intel_fpga_pcie *pcie = dev_get_priv(bus); @@ -326,7 +326,7 @@ static int _pcie_intel_fpga_write_config(struct intel_fpga_pcie *pcie, byte_en, data); } -static int pcie_intel_fpga_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_intel_fpga_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_layerscape.c b/drivers/pci/pcie_layerscape.c index 2ab67d1fc9..8b313e9278 100644 --- a/drivers/pci/pcie_layerscape.c +++ b/drivers/pci/pcie_layerscape.c @@ -243,7 +243,7 @@ static int ls_pcie_addr_valid(struct ls_pcie *pcie, pci_dev_t bdf) return 0; } -int ls_pcie_conf_address(struct udevice *bus, pci_dev_t bdf, +int ls_pcie_conf_address(const struct udevice *bus, pci_dev_t bdf, uint offset, void **paddress) { struct ls_pcie *pcie = dev_get_priv(bus); @@ -271,7 +271,7 @@ int ls_pcie_conf_address(struct udevice *bus, pci_dev_t bdf, return 0; } -static int ls_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int ls_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_layerscape_gen4.c b/drivers/pci/pcie_layerscape_gen4.c index 1fd8761bbc..cec61fa7d6 100644 --- a/drivers/pci/pcie_layerscape_gen4.c +++ b/drivers/pci/pcie_layerscape_gen4.c @@ -227,7 +227,7 @@ void *ls_pcie_g4_conf_address(struct ls_pcie_g4 *pcie, pci_dev_t bdf, return pcie->cfg + offset; } -static int ls_pcie_g4_read_config(struct udevice *bus, pci_dev_t bdf, +static int ls_pcie_g4_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_mediatek.c b/drivers/pci/pcie_mediatek.c index a0dcb258b0..0b412aca0e 100644 --- a/drivers/pci/pcie_mediatek.c +++ b/drivers/pci/pcie_mediatek.c @@ -66,7 +66,7 @@ struct mtk_pcie { struct list_head ports; }; -static int mtk_pcie_config_address(struct udevice *udev, pci_dev_t bdf, +static int mtk_pcie_config_address(const struct udevice *udev, pci_dev_t bdf, uint offset, void **paddress) { struct mtk_pcie *pcie = dev_get_priv(udev); @@ -77,7 +77,7 @@ static int mtk_pcie_config_address(struct udevice *udev, pci_dev_t bdf, return 0; } -static int mtk_pcie_read_config(struct udevice *bus, pci_dev_t bdf, +static int mtk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_phytium.c b/drivers/pci/pcie_phytium.c index 92e281e7c2..51b2171f9f 100644 --- a/drivers/pci/pcie_phytium.c +++ b/drivers/pci/pcie_phytium.c @@ -75,9 +75,8 @@ static int phytium_pci_skip_dev(pci_dev_t parent) * code. Otherwise the address to access will be written to the pointer pointed * to by @paddress. */ -static int pci_phytium_conf_address(struct udevice *bus, pci_dev_t bdf, - uint offset, - void **paddress) +static int pci_phytium_conf_address(const struct udevice *bus, pci_dev_t bdf, + uint offset, void **paddress) { struct phytium_pcie *pcie = dev_get_priv(bus); void *addr; @@ -119,7 +118,7 @@ static int pci_phytium_conf_address(struct udevice *bus, pci_dev_t bdf, * space of the device identified by the bus, device & function numbers in @bdf * on the PCI bus @bus. */ -static int pci_phytium_read_config(struct udevice *bus, pci_dev_t bdf, +static int pci_phytium_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/pci/pcie_xilinx.c b/drivers/pci/pcie_xilinx.c index 44a5f1e1f4..05787ae144 100644 --- a/drivers/pci/pcie_xilinx.c +++ b/drivers/pci/pcie_xilinx.c @@ -54,7 +54,7 @@ static bool pcie_xilinx_link_up(struct xilinx_pcie *pcie) * * Return: 0 on success, else -ENODEV */ -static int pcie_xilinx_config_address(struct udevice *udev, pci_dev_t bdf, +static int pcie_xilinx_config_address(const struct udevice *udev, pci_dev_t bdf, uint offset, void **paddress) { struct xilinx_pcie *pcie = dev_get_priv(udev); @@ -97,7 +97,7 @@ static int pcie_xilinx_config_address(struct udevice *udev, pci_dev_t bdf, * * Return: 0 on success, else -ENODEV or -EINVAL */ -static int pcie_xilinx_read_config(struct udevice *bus, pci_dev_t bdf, +static int pcie_xilinx_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { diff --git a/drivers/power/acpi_pmc/pmc_emul.c b/drivers/power/acpi_pmc/pmc_emul.c index 15cc7acaf3..dfff335e54 100644 --- a/drivers/power/acpi_pmc/pmc_emul.c +++ b/drivers/power/acpi_pmc/pmc_emul.c @@ -42,7 +42,7 @@ struct pmc_emul_priv { u8 regs[MEMMAP_SIZE]; }; -static int sandbox_pmc_emul_read_config(struct udevice *emul, uint offset, +static int sandbox_pmc_emul_read_config(const struct udevice *emul, uint offset, ulong *valuep, enum pci_size_t size) { struct pmc_emul_platdata *plat = dev_get_platdata(emul); diff --git a/include/pci.h b/include/pci.h index 8c761d8da3..40e3c3fc6f 100644 --- a/include/pci.h +++ b/include/pci.h @@ -899,8 +899,8 @@ struct dm_pci_ops { * @size: Access size * @return 0 if OK, -ve on error */ - int (*read_config)(struct udevice *bus, pci_dev_t bdf, uint offset, - ulong *valuep, enum pci_size_t size); + int (*read_config)(const struct udevice *bus, pci_dev_t bdf, + uint offset, ulong *valuep, enum pci_size_t size); /** * write_config() - Write a PCI configuration value * @@ -974,7 +974,7 @@ int dm_pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp); * @devp: Returns the device for this address, if found * @return 0 if OK, -ENODEV if not found */ -int pci_bus_find_devfn(struct udevice *bus, pci_dev_t find_devfn, +int pci_bus_find_devfn(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **devp); /** @@ -1155,8 +1155,9 @@ int pci_read_config8(pci_dev_t pcidev, int offset, u8 *valuep); * Return: 0 on success, else -EINVAL */ int pci_generic_mmap_write_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong value, @@ -1180,8 +1181,9 @@ int pci_generic_mmap_write_config( * Return: 0 on success, else -EINVAL */ int pci_generic_mmap_read_config( - struct udevice *bus, - int (*addr_f)(struct udevice *bus, pci_dev_t bdf, uint offset, void **addrp), + const struct udevice *bus, + int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, + void **addrp), pci_dev_t bdf, uint offset, ulong *valuep, @@ -1523,8 +1525,8 @@ struct dm_pci_emul_ops { * @size: Access size * @return 0 if OK, -ve on error */ - int (*read_config)(struct udevice *dev, uint offset, ulong *valuep, - enum pci_size_t size); + int (*read_config)(const struct udevice *dev, uint offset, + ulong *valuep, enum pci_size_t size); /** * write_config() - Write a PCI configuration value * @@ -1609,7 +1611,7 @@ struct dm_pci_emul_ops { * @emulp: Returns emulated device if found * @return 0 if found, -ENODEV if not found */ -int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, +int sandbox_pci_get_emul(const struct udevice *bus, pci_dev_t find_devfn, struct udevice **containerp, struct udevice **emulp); /** From patchwork Mon Jan 27 15:49:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229904 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=bBjyuygj; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vNW0PFGz9sPJ for ; Tue, 28 Jan 2020 02:50:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C693581A23; Mon, 27 Jan 2020 16:50:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="bBjyuygj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AA5D281A22; Mon, 27 Jan 2020 16:50:21 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (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 10EC881A15 for ; Mon, 27 Jan 2020 16:50:12 +0100 (CET) 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-io1-xd43.google.com with SMTP id i11so10478503ioi.12 for ; Mon, 27 Jan 2020 07:50:12 -0800 (PST) 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=av+9DaeFqGUTPSxFt+I9zFT3h75G7Ynix1geeZDDV84=; b=bBjyuygjdq2iqA2nNstBDPexthzXUdH8tOygR/jVnJNkN5CrIWbFF1FMEQMBCG62Er nyvGUsWdzr6ovSo8IxiFw1NMpM3o6dfDoJBS6pF4ln28uDgqRxeayXG1UypBdKQzpKGO Gknj2ZVztASFsxwKEyqyHjPDvyZfrmXMszQnQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=av+9DaeFqGUTPSxFt+I9zFT3h75G7Ynix1geeZDDV84=; b=OIAI6kMcA+LgR+V4hgpVf4gm9BwqRasjPvX5fMk2ycyIU+2eUhB1SLFgOTJKqztn4l m8uBFm738tknj8nw8FiUe/s4pVmzhCKa4DpcamACJ7eekjYrluxiRwwCny9gCbUDlNum 4050l8G8B49Fw3w/3kmLYNSLg1KFtXjxVEoavHkUN4ws5+EP2AT9uMNmPnuH/tBZ6WrH OFvHm+jk/8pCGoGVURgxIh704+rYHfzg3x1H7Qvr/g1JUnV+iTk1McXwBvcDiUXQbavu u755G0Orz7FbzTqoMd7stzl1mUu48wkC8MZUXNyxf5lDfiHNfKABtuBIoKqNrQIRhy6O 1kLg== X-Gm-Message-State: APjAAAUCLadr7VaN1LfEnY0KTvhWpaJ3/JJtULirjvOjuQfJOBdLQqSy c7q/jlzF4YnBnhrBZxneYtrio+WjBRI= X-Google-Smtp-Source: APXvYqyHv0GlNud0k8zXQhcfCPHvccCEi49m+cyxj4I8kwKQMeLKoSBg0Ut6Zw0ZYgfLAwPHrsJjAw== X-Received: by 2002:a02:cc41:: with SMTP id i1mr11581297jaq.71.1580140211371; Mon, 27 Jan 2020 07:50:11 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:11 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 03/21] dm: pci: Update a few more interfaces for const udevice * Date: Mon, 27 Jan 2020 08:49:38 -0700 Message-Id: <20200127084920.3.I36b78dcb38fa3d0b3f6ca37cdcc6b8df09a2ae22@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ramon Fried , Stefan Roese , Thierry Reding , Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Tidy up a few places where const * should be used. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/pci/pci-uclass.c | 18 +++++++++--------- include/fdtdec.h | 2 +- include/pci.h | 16 ++++++++-------- lib/fdtdec.c | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 78d4129572..5f318120e1 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -43,7 +43,7 @@ struct udevice *pci_get_controller(struct udevice *dev) return dev; } -pci_dev_t dm_pci_get_bdf(struct udevice *dev) +pci_dev_t dm_pci_get_bdf(const struct udevice *dev) { struct pci_child_platdata *pplat = dev_get_parent_platdata(dev); struct udevice *bus = dev->parent; @@ -349,7 +349,7 @@ int dm_pci_write_config32(struct udevice *dev, int offset, u32 value) return dm_pci_write_config(dev, offset, value, PCI_SIZE_32); } -int pci_bus_read_config(struct udevice *bus, pci_dev_t bdf, int offset, +int pci_bus_read_config(const struct udevice *bus, pci_dev_t bdf, int offset, unsigned long *valuep, enum pci_size_t size) { struct dm_pci_ops *ops; @@ -373,10 +373,10 @@ int pci_read_config(pci_dev_t bdf, int offset, unsigned long *valuep, return pci_bus_read_config(bus, bdf, offset, valuep, size); } -int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep, - enum pci_size_t size) +int dm_pci_read_config(const struct udevice *dev, int offset, + unsigned long *valuep, enum pci_size_t size) { - struct udevice *bus; + const struct udevice *bus; for (bus = dev; device_is_on_pci_bus(bus);) bus = bus->parent; @@ -423,7 +423,7 @@ int pci_read_config8(pci_dev_t bdf, int offset, u8 *valuep) return 0; } -int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep) +int dm_pci_read_config8(const struct udevice *dev, int offset, u8 *valuep) { unsigned long value; int ret; @@ -436,7 +436,7 @@ int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep) return 0; } -int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep) +int dm_pci_read_config16(const struct udevice *dev, int offset, u16 *valuep) { unsigned long value; int ret; @@ -449,7 +449,7 @@ int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep) return 0; } -int dm_pci_read_config32(struct udevice *dev, int offset, u32 *valuep) +int dm_pci_read_config32(const struct udevice *dev, int offset, u32 *valuep) { unsigned long value; int ret; @@ -1203,7 +1203,7 @@ int pci_get_regions(struct udevice *dev, struct pci_region **iop, return (*iop != NULL) + (*memp != NULL) + (*prefp != NULL); } -u32 dm_pci_read_bar32(struct udevice *dev, int barnum) +u32 dm_pci_read_bar32(const struct udevice *dev, int barnum) { u32 addr; int bar; diff --git a/include/fdtdec.h b/include/fdtdec.h index c8a143db5f..166f29c55b 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -441,7 +441,7 @@ int fdtdec_get_pci_vendev(const void *blob, int node, * @param bar returns base address of the pci device's registers * @return 0 if ok, negative on error */ -int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, +int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr, u32 *bar); /** diff --git a/include/pci.h b/include/pci.h index 40e3c3fc6f..50ca249f2d 100644 --- a/include/pci.h +++ b/include/pci.h @@ -924,7 +924,7 @@ struct dm_pci_ops { * @dev: Device to check * @return bus/device/function value (see PCI_BDF()) */ -pci_dev_t dm_pci_get_bdf(struct udevice *dev); +pci_dev_t dm_pci_get_bdf(const struct udevice *dev); /** * pci_bind_bus_devices() - scan a PCI bus and bind devices @@ -1067,7 +1067,7 @@ int dm_pci_hose_probe_bus(struct udevice *bus); * @size: Access size * @return 0 if OK, -ve on error */ -int pci_bus_read_config(struct udevice *bus, pci_dev_t bdf, int offset, +int pci_bus_read_config(const struct udevice *bus, pci_dev_t bdf, int offset, unsigned long *valuep, enum pci_size_t size); /** @@ -1102,12 +1102,12 @@ int pci_bus_clrset_config32(struct udevice *bus, pci_dev_t bdf, int offset, * Driver model PCI config access functions. Use these in preference to others * when you have a valid device */ -int dm_pci_read_config(struct udevice *dev, int offset, unsigned long *valuep, - enum pci_size_t size); +int dm_pci_read_config(const struct udevice *dev, int offset, + unsigned long *valuep, enum pci_size_t size); -int dm_pci_read_config8(struct udevice *dev, int offset, u8 *valuep); -int dm_pci_read_config16(struct udevice *dev, int offset, u16 *valuep); -int dm_pci_read_config32(struct udevice *dev, int offset, u32 *valuep); +int dm_pci_read_config8(const struct udevice *dev, int offset, u8 *valuep); +int dm_pci_read_config16(const struct udevice *dev, int offset, u16 *valuep); +int dm_pci_read_config32(const struct udevice *dev, int offset, u32 *valuep); int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value, enum pci_size_t size); @@ -1313,7 +1313,7 @@ void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr); * @barnum: Bar number to read (numbered from 0) * @return: value of BAR */ -u32 dm_pci_read_bar32(struct udevice *dev, int barnum); +u32 dm_pci_read_bar32(const struct udevice *dev, int barnum); /** * dm_pci_bus_to_phys() - convert a PCI bus address to a physical address diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 17051d409c..7fbb4c7ddc 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -224,7 +224,7 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device) return -ENOENT; } -int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, +int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr, u32 *bar) { int barnum; From patchwork Mon Jan 27 15:49:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229906 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Yo84nD5p; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vNy4SSdz9sPJ for ; Tue, 28 Jan 2020 02:51:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6A64881A11; Mon, 27 Jan 2020 16:50:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Yo84nD5p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3534181A21; Mon, 27 Jan 2020 16:50:23 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 C4DCE81A10 for ; Mon, 27 Jan 2020 16:50:13 +0100 (CET) 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-io1-xd44.google.com with SMTP id n11so10498767iom.9 for ; Mon, 27 Jan 2020 07:50:13 -0800 (PST) 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=6K1gGcQ/hdkwirfDK45hqTFrS9o53AOmN7E46knJa1k=; b=Yo84nD5p741bIieoGalPj48czUAZHabAT7T90jZjissQRzKcxSqeNMdnYui2qF4/je uxmLlQxGUkyz8jZRqh8aS1paI4sTXL+BAF5ulBCigta1ymDDUoOe1LLcZFx5HN+3MfX4 SR8jS/Aa4JdIPw0nAHQoJtnyURRSZsncihb0s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6K1gGcQ/hdkwirfDK45hqTFrS9o53AOmN7E46knJa1k=; b=EcT7e+qDSR5hRHbUDynMivrPQxPM8BCXdy24EPqvmG94XcTCh/zmkTpzt7l5E+hlPR 3hKVAGwGYDX7PRCU0PPaCMwz6ktPB4QyqWDaqQ/YUXRnvsw+Z0HhRtL/DAPVXKgbkiFz WGjuRQj+qM52YDS1IuOy0Fftw+AogXRxP7ThllOTFDhACB85fxdigioslwlSplyA6p8M insfN1G8IgX7DD7jxuP/XU2kQpsItV7sTtN3rhq4X/UIbxyWw5OcJ4dHHSYdJTulSERO w27LrO3avk3wZcf0KPEOjC4zmNNDRoFWq03Uer76YvLuXerP+iCnB8WOqJgAVITPV7Wd 4i6w== X-Gm-Message-State: APjAAAXTz6k1fe42b0m/hKiUT7yLbfDYVUQZxUBgpUdy6xnzayPSNmMz 2NUHnWNvZVATEb6F3drLsj8epI0yKnI= X-Google-Smtp-Source: APXvYqz8iG+rdafO0ZvDnZAh6nvNJDdXF3uNvB+kmUW3lMgzcUasYMkj34M7261WEZcaL0alypyqvA== X-Received: by 2002:a5d:8555:: with SMTP id b21mr12987074ios.200.1580140212171; Mon, 27 Jan 2020 07:50:12 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:11 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 04/21] dm: core: Use const device for the devfdt...() interface Date: Mon, 27 Jan 2020 08:49:39 -0700 Message-Id: <20200127084920.4.I875a778e957587ebdead7b7a09d91ba410ad9d08@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean These functions do not modify the device so should use a const pointer to it. Update the code accordingly. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/fdtaddr.c | 26 +++++++++++++------------- include/dm/fdtaddr.h | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 575798fae9..33811e62f7 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -16,7 +16,7 @@ DECLARE_GLOBAL_DATA_PTR; -fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index) +fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index) { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) fdt_addr_t addr; @@ -91,8 +91,8 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index) #endif } -fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, - fdt_size_t *size) +fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, + fdt_size_t *size) { #if CONFIG_IS_ENABLED(OF_CONTROL) /* @@ -113,7 +113,7 @@ fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, #endif } -fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name) +fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name) { #if CONFIG_IS_ENABLED(OF_CONTROL) int index; @@ -129,8 +129,8 @@ fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name) #endif } -fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, - fdt_size_t *size) +fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, + const char *name, fdt_size_t *size) { #if CONFIG_IS_ENABLED(OF_CONTROL) int index; @@ -146,17 +146,17 @@ fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, #endif } -fdt_addr_t devfdt_get_addr(struct udevice *dev) +fdt_addr_t devfdt_get_addr(const struct udevice *dev) { return devfdt_get_addr_index(dev, 0); } -void *devfdt_get_addr_ptr(struct udevice *dev) +void *devfdt_get_addr_ptr(const struct udevice *dev) { return (void *)(uintptr_t)devfdt_get_addr_index(dev, 0); } -void *devfdt_remap_addr_index(struct udevice *dev, int index) +void *devfdt_remap_addr_index(const struct udevice *dev, int index) { fdt_addr_t addr = devfdt_get_addr_index(dev, index); @@ -166,7 +166,7 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index) return map_physmem(addr, 0, MAP_NOCACHE); } -void *devfdt_remap_addr_name(struct udevice *dev, const char *name) +void *devfdt_remap_addr_name(const struct udevice *dev, const char *name) { fdt_addr_t addr = devfdt_get_addr_name(dev, name); @@ -176,12 +176,12 @@ void *devfdt_remap_addr_name(struct udevice *dev, const char *name) return map_physmem(addr, 0, MAP_NOCACHE); } -void *devfdt_remap_addr(struct udevice *dev) +void *devfdt_remap_addr(const struct udevice *dev) { return devfdt_remap_addr_index(dev, 0); } -void *devfdt_map_physmem(struct udevice *dev, unsigned long size) +void *devfdt_map_physmem(const struct udevice *dev, unsigned long size) { fdt_addr_t addr = devfdt_get_addr(dev); @@ -191,7 +191,7 @@ void *devfdt_map_physmem(struct udevice *dev, unsigned long size) return map_physmem(addr, size, MAP_NOCACHE); } -fdt_addr_t devfdt_get_addr_pci(struct udevice *dev) +fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev) { ulong addr; diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index 959d3bc2d6..a4fda581a7 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -21,7 +21,7 @@ struct udevice; * * @return addr */ -fdt_addr_t devfdt_get_addr(struct udevice *dev); +fdt_addr_t devfdt_get_addr(const struct udevice *dev); /** * devfdt_get_addr_ptr() - Return pointer to the address of the reg property @@ -31,7 +31,7 @@ fdt_addr_t devfdt_get_addr(struct udevice *dev); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_get_addr_ptr(struct udevice *dev); +void *devfdt_get_addr_ptr(const struct udevice *dev); /** * devfdt_remap_addr() - Return pointer to the memory-mapped I/O address @@ -41,7 +41,7 @@ void *devfdt_get_addr_ptr(struct udevice *dev); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_remap_addr(struct udevice *dev); +void *devfdt_remap_addr(const struct udevice *dev); /** * devfdt_remap_addr_index() - Return indexed pointer to the memory-mapped @@ -53,7 +53,7 @@ void *devfdt_remap_addr(struct udevice *dev); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_remap_addr_index(struct udevice *dev, int index); +void *devfdt_remap_addr_index(const struct udevice *dev, int index); /** * devfdt_remap_addr_name() - Get the reg property of a device, indexed by @@ -66,7 +66,7 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index); * * @return Pointer to addr, or NULL if there is no such property */ -void *devfdt_remap_addr_name(struct udevice *dev, const char *name); +void *devfdt_remap_addr_name(const struct udevice *dev, const char *name); /** * devfdt_map_physmem() - Read device address from reg property of the @@ -79,7 +79,7 @@ void *devfdt_remap_addr_name(struct udevice *dev, const char *name); * @return mapped address, or NULL if the device does not have reg * property. */ -void *devfdt_map_physmem(struct udevice *dev, unsigned long size); +void *devfdt_map_physmem(const struct udevice *dev, unsigned long size); /** * devfdt_get_addr_index() - Get the indexed reg property of a device @@ -90,7 +90,7 @@ void *devfdt_map_physmem(struct udevice *dev, unsigned long size); * * @return addr */ -fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index); +fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index); /** * devfdt_get_addr_size_index() - Get the indexed reg property of a device @@ -105,8 +105,8 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index); * * @return addr */ -fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, - fdt_size_t *size); +fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, + fdt_size_t *size); /** * devfdt_get_addr_name() - Get the reg property of a device, indexed by name @@ -118,7 +118,7 @@ fdt_addr_t devfdt_get_addr_size_index(struct udevice *dev, int index, * * @return addr */ -fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name); +fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); /** * devfdt_get_addr_size_name() - Get the reg property and its size for a device, @@ -135,8 +135,8 @@ fdt_addr_t devfdt_get_addr_name(struct udevice *dev, const char *name); * * @return addr */ -fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, - fdt_size_t *size); +fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, + const char *name, fdt_size_t *size); /** * devfdt_get_addr_pci() - Read an address and handle PCI address translation @@ -144,6 +144,6 @@ fdt_addr_t devfdt_get_addr_size_name(struct udevice *dev, const char *name, * @dev: Device to read from * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t devfdt_get_addr_pci(struct udevice *dev); +fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev); #endif From patchwork Mon Jan 27 15:49:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229908 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=a+Km/BPW; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vPS5By7z9sPJ for ; Tue, 28 Jan 2020 02:51:40 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B239181A21; Mon, 27 Jan 2020 16:50:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="a+Km/BPW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E351A81A1E; Mon, 27 Jan 2020 16:50:24 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 0EC8B819A9 for ; Mon, 27 Jan 2020 16:50:14 +0100 (CET) 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-io1-xd41.google.com with SMTP id i11so10478642ioi.12 for ; Mon, 27 Jan 2020 07:50:14 -0800 (PST) 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=fkd1Kqs6sLBycdoN7+kR6zN8BwBg1KyWidMwTMlD/A0=; b=a+Km/BPWoxNhqG5ZK0qVLDK1uEWzIKqY360VGDBfor4sWhL5PvTQhqpISDrkOdzFBO LXPElv1YYEW5M1JBQeIT9XghvcC10izteMYZOAIFHrXSpxv9w/tHSYOggpBeEvioMDNA OlyWlWeuij31Vj/r5UcndHo8/lO1NlBHi6m8o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fkd1Kqs6sLBycdoN7+kR6zN8BwBg1KyWidMwTMlD/A0=; b=Xoiq8xjnNliov1NG9oOJ5D64zue5Rqbh5BsiIkzOM7Fd/AsDUzT4hfXlj9Aqk3r909 sN4U/ak3v3/R/oiVVHc2iPib5PgUiVy3sNyp4tpDdcPJaQwJWdZ14QhwmHz9LjO420ri acW0Ba+Z/wJ+RmP9ZDW0YEwdTkudlB+vBjBkBO1/0sVkKYx8HHlS0NfQGvfhsEahuhxA rgzTzcnYl9skoH+KwYE4PDWeHKNn2IbJnXjgeVsIk6GtG3E8XxrdHf1zGcz+g27yhC/p QkRVXKPxcvFyNccPnH8FxnuNQeHaYnmDgo7Vz/bIYIYlnG5u6vBjQ2valihRA6cAQQ6t fAfg== X-Gm-Message-State: APjAAAW+jaLxxHwWbPYDPNIpvl8j5j60AYjdvM1UxuZyIY33vNOrS7Sl fG5vghpdr3DeBnsVMR1k2yHgNi6DLz4= X-Google-Smtp-Source: APXvYqyu5EpGuZOamYbsjRSHYhYPrrUSkVnLpFAN/s/flXTC07M1y1zxthwRYBXHaTm57u3fmBjgdw== X-Received: by 2002:a6b:b745:: with SMTP id h66mr12790998iof.128.1580140213093; Mon, 27 Jan 2020 07:50:13 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:12 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 05/21] dm: core: Use const device for the dev_read_...() interface Date: Mon, 27 Jan 2020 08:49:40 -0700 Message-Id: <20200127084920.5.I875a778e957587ebdead7b7a09d91ba410ad9d08@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean These functions do not modify the device so should use a const pointer to it. Update the code accordingly. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/read.c | 97 +++++++++++---------- include/dm/read.h | 205 +++++++++++++++++++++++--------------------- 2 files changed, 159 insertions(+), 143 deletions(-) diff --git a/drivers/core/read.c b/drivers/core/read.c index 9602e52d1b..1f999b1b31 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -11,27 +11,29 @@ #include #include -int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp) +int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp) { return ofnode_read_u32(dev_ofnode(dev), propname, outp); } -int dev_read_u32_default(struct udevice *dev, const char *propname, int def) +int dev_read_u32_default(const struct udevice *dev, const char *propname, + int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } -int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp) +int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp) { return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp); } -int dev_read_s32_default(struct udevice *dev, const char *propname, int def) +int dev_read_s32_default(const struct udevice *dev, const char *propname, + int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } -int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp) +int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp) { u32 val; int ret; @@ -44,32 +46,33 @@ int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp) return 0; } -int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp) +int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp) { return ofnode_read_u64(dev_ofnode(dev), propname, outp); } -u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def) +u64 dev_read_u64_default(const struct udevice *dev, const char *propname, + u64 def) { return ofnode_read_u64_default(dev_ofnode(dev), propname, def); } -const char *dev_read_string(struct udevice *dev, const char *propname) +const char *dev_read_string(const struct udevice *dev, const char *propname) { return ofnode_read_string(dev_ofnode(dev), propname); } -bool dev_read_bool(struct udevice *dev, const char *propname) +bool dev_read_bool(const struct udevice *dev, const char *propname) { return ofnode_read_bool(dev_ofnode(dev), propname); } -ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name) +ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name) { return ofnode_find_subnode(dev_ofnode(dev), subnode_name); } -ofnode dev_read_first_subnode(struct udevice *dev) +ofnode dev_read_first_subnode(const struct udevice *dev) { return ofnode_first_subnode(dev_ofnode(dev)); } @@ -79,12 +82,12 @@ ofnode dev_read_next_subnode(ofnode node) return ofnode_next_subnode(node); } -int dev_read_size(struct udevice *dev, const char *propname) +int dev_read_size(const struct udevice *dev, const char *propname) { return ofnode_read_size(dev_ofnode(dev), propname); } -fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) +fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index) { if (ofnode_is_np(dev_ofnode(dev))) return ofnode_get_addr_index(dev_ofnode(dev), index); @@ -92,7 +95,7 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) return devfdt_get_addr_index(dev, index); } -fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, +fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size) { if (ofnode_is_np(dev_ofnode(dev))) @@ -101,7 +104,7 @@ fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, return devfdt_get_addr_size_index(dev, index, size); } -void *dev_remap_addr_index(struct udevice *dev, int index) +void *dev_remap_addr_index(const struct udevice *dev, int index) { fdt_addr_t addr = dev_read_addr_index(dev, index); @@ -111,7 +114,7 @@ void *dev_remap_addr_index(struct udevice *dev, int index) return map_physmem(addr, 0, MAP_NOCACHE); } -fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name) +fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) { int index = dev_read_stringlist_search(dev, "reg-names", name); @@ -121,7 +124,7 @@ fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name) return dev_read_addr_index(dev, index); } -fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, +fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) { int index = dev_read_stringlist_search(dev, "reg-names", name); @@ -132,7 +135,7 @@ fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, return dev_read_addr_size_index(dev, index, size); } -void *dev_remap_addr_name(struct udevice *dev, const char *name) +void *dev_remap_addr_name(const struct udevice *dev, const char *name) { fdt_addr_t addr = dev_read_addr_name(dev, name); @@ -142,52 +145,52 @@ void *dev_remap_addr_name(struct udevice *dev, const char *name) return map_physmem(addr, 0, MAP_NOCACHE); } -fdt_addr_t dev_read_addr(struct udevice *dev) +fdt_addr_t dev_read_addr(const struct udevice *dev) { return dev_read_addr_index(dev, 0); } -void *dev_read_addr_ptr(struct udevice *dev) +void *dev_read_addr_ptr(const struct udevice *dev) { fdt_addr_t addr = dev_read_addr(dev); return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0); } -void *dev_remap_addr(struct udevice *dev) +void *dev_remap_addr(const struct udevice *dev) { return dev_remap_addr_index(dev, 0); } -fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property, +fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *property, fdt_size_t *sizep) { return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); } -const char *dev_read_name(struct udevice *dev) +const char *dev_read_name(const struct udevice *dev) { return ofnode_get_name(dev_ofnode(dev)); } -int dev_read_stringlist_search(struct udevice *dev, const char *property, +int dev_read_stringlist_search(const struct udevice *dev, const char *property, const char *string) { return ofnode_stringlist_search(dev_ofnode(dev), property, string); } -int dev_read_string_index(struct udevice *dev, const char *propname, int index, - const char **outp) +int dev_read_string_index(const struct udevice *dev, const char *propname, + int index, const char **outp) { return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); } -int dev_read_string_count(struct udevice *dev, const char *propname) +int dev_read_string_count(const struct udevice *dev, const char *propname) { return ofnode_read_string_count(dev_ofnode(dev), propname); } -int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, +int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args) { @@ -196,34 +199,34 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, out_args); } -int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name) +int dev_count_phandle_with_args(const struct udevice *dev, + const char *list_name, const char *cells_name) { return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, cells_name); } -int dev_read_addr_cells(struct udevice *dev) +int dev_read_addr_cells(const struct udevice *dev) { return ofnode_read_addr_cells(dev_ofnode(dev)); } -int dev_read_size_cells(struct udevice *dev) +int dev_read_size_cells(const struct udevice *dev) { return ofnode_read_size_cells(dev_ofnode(dev)); } -int dev_read_simple_addr_cells(struct udevice *dev) +int dev_read_simple_addr_cells(const struct udevice *dev) { return ofnode_read_simple_addr_cells(dev_ofnode(dev)); } -int dev_read_simple_size_cells(struct udevice *dev) +int dev_read_simple_size_cells(const struct udevice *dev) { return ofnode_read_simple_size_cells(dev_ofnode(dev)); } -int dev_read_phandle(struct udevice *dev) +int dev_read_phandle(const struct udevice *dev) { ofnode node = dev_ofnode(dev); @@ -233,12 +236,13 @@ int dev_read_phandle(struct udevice *dev) return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); } -const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp) +const void *dev_read_prop(const struct udevice *dev, const char *propname, + int *lenp) { return ofnode_get_property(dev_ofnode(dev), propname, lenp); } -int dev_read_alias_seq(struct udevice *dev, int *devnump) +int dev_read_alias_seq(const struct udevice *dev, int *devnump) { ofnode node = dev_ofnode(dev); const char *uc_name = dev->uclass->uc_drv->name; @@ -256,19 +260,19 @@ int dev_read_alias_seq(struct udevice *dev, int *devnump) return ret; } -int dev_read_u32_array(struct udevice *dev, const char *propname, +int dev_read_u32_array(const struct udevice *dev, const char *propname, u32 *out_values, size_t sz) { return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); } -const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, - size_t sz) +const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, + const char *propname, size_t sz) { return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } -int dev_read_enabled(struct udevice *dev) +int dev_read_enabled(const struct udevice *dev) { ofnode node = dev_ofnode(dev); @@ -279,23 +283,24 @@ int dev_read_enabled(struct udevice *dev) ofnode_to_offset(node)); } -int dev_read_resource(struct udevice *dev, uint index, struct resource *res) +int dev_read_resource(const struct udevice *dev, uint index, + struct resource *res) { return ofnode_read_resource(dev_ofnode(dev), index, res); } -int dev_read_resource_byname(struct udevice *dev, const char *name, +int dev_read_resource_byname(const struct udevice *dev, const char *name, struct resource *res) { return ofnode_read_resource_byname(dev_ofnode(dev), name, res); } -u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) +u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr) { return ofnode_translate_address(dev_ofnode(dev), in_addr); } -u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr) +u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr) { return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); } @@ -308,7 +313,7 @@ int dev_read_alias_highest_id(const char *stem) return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); } -fdt_addr_t dev_read_addr_pci(struct udevice *dev) +fdt_addr_t dev_read_addr_pci(const struct udevice *dev) { ulong addr; diff --git a/include/dm/read.h b/include/dm/read.h index f1c1553f80..92a7328fc8 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -16,12 +16,12 @@ struct resource; #if CONFIG_IS_ENABLED(OF_LIVE) -static inline const struct device_node *dev_np(struct udevice *dev) +static inline const struct device_node *dev_np(const struct udevice *dev) { return ofnode_to_np(dev->node); } #else -static inline const struct device_node *dev_np(struct udevice *dev) +static inline const struct device_node *dev_np(const struct udevice *dev) { return NULL; } @@ -53,7 +53,7 @@ static inline bool dev_of_valid(const struct udevice *dev) * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); +int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp); /** * dev_read_u32_default() - read a 32-bit integer from a device's DT property @@ -63,7 +63,8 @@ int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); * @def: default value to return if the property has no value * @return property value, or @def if not found */ -int dev_read_u32_default(struct udevice *dev, const char *propname, int def); +int dev_read_u32_default(const struct udevice *dev, const char *propname, + int def); /** * dev_read_s32() - read a signed 32-bit integer from a device's DT property @@ -73,7 +74,7 @@ int dev_read_u32_default(struct udevice *dev, const char *propname, int def); * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp); +int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp); /** * dev_read_s32_default() - read a signed 32-bit int from a device's DT property @@ -83,7 +84,8 @@ int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp); * @def: default value to return if the property has no value * @return property value, or @def if not found */ -int dev_read_s32_default(struct udevice *dev, const char *propname, int def); +int dev_read_s32_default(const struct udevice *dev, const char *propname, + int def); /** * dev_read_u32u() - read a 32-bit integer from a device's DT property @@ -95,7 +97,7 @@ int dev_read_s32_default(struct udevice *dev, const char *propname, int def); * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp); +int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp); /** * dev_read_u64() - read a 64-bit integer from a device's DT property @@ -105,7 +107,7 @@ int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp); * @outp: place to put value (if found) * @return 0 if OK, -ve on error */ -int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp); +int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp); /** * dev_read_u64_default() - read a 64-bit integer from a device's DT property @@ -115,7 +117,8 @@ int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp); * @def: default value to return if the property has no value * @return property value, or @def if not found */ -u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def); +u64 dev_read_u64_default(const struct udevice *dev, const char *propname, + u64 def); /** * dev_read_string() - Read a string from a device's DT property @@ -124,7 +127,7 @@ u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def); * @propname: name of the property to read * @return string from property value, or NULL if there is no such property */ -const char *dev_read_string(struct udevice *dev, const char *propname); +const char *dev_read_string(const struct udevice *dev, const char *propname); /** * dev_read_bool() - read a boolean value from a device's DT property @@ -133,7 +136,7 @@ const char *dev_read_string(struct udevice *dev, const char *propname); * @propname: name of property to read * @return true if property is present (meaning true), false if not present */ -bool dev_read_bool(struct udevice *dev, const char *propname); +bool dev_read_bool(const struct udevice *dev, const char *propname); /** * dev_read_subnode() - find a named subnode of a device @@ -143,7 +146,7 @@ bool dev_read_bool(struct udevice *dev, const char *propname); * @return reference to subnode (which can be invalid if there is no such * subnode) */ -ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); +ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name); /** * dev_read_size() - read the size of a property @@ -152,7 +155,7 @@ ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); * @propname: property to check * @return size of property if present, or -EINVAL if not */ -int dev_read_size(struct udevice *dev, const char *propname); +int dev_read_size(const struct udevice *dev, const char *propname); /** * dev_read_addr_index() - Get the indexed reg property of a device @@ -163,7 +166,7 @@ int dev_read_size(struct udevice *dev, const char *propname); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); +fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index); /** * dev_read_addr_size_index() - Get the indexed reg property of a device @@ -175,7 +178,7 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, +fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size); /** @@ -188,7 +191,7 @@ fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, * * @return pointer or NULL if not found */ -void *dev_remap_addr_index(struct udevice *dev, int index); +void *dev_remap_addr_index(const struct udevice *dev, int index); /** * dev_read_addr_name() - Get the reg property of a device, indexed by name @@ -200,7 +203,7 @@ void *dev_remap_addr_index(struct udevice *dev, int index); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); +fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name); /** * dev_read_addr_size_name() - Get the reg property of a device, indexed by name @@ -213,7 +216,7 @@ fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, +fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size); /** @@ -227,7 +230,7 @@ fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, * * @return pointer or NULL if not found */ -void *dev_remap_addr_name(struct udevice *dev, const char* name); +void *dev_remap_addr_name(const struct udevice *dev, const char *name); /** * dev_read_addr() - Get the reg property of a device @@ -236,7 +239,7 @@ void *dev_remap_addr_name(struct udevice *dev, const char* name); * * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr(struct udevice *dev); +fdt_addr_t dev_read_addr(const struct udevice *dev); /** * dev_read_addr_ptr() - Get the reg property of a device @@ -246,7 +249,7 @@ fdt_addr_t dev_read_addr(struct udevice *dev); * * @return pointer or NULL if not found */ -void *dev_read_addr_ptr(struct udevice *dev); +void *dev_read_addr_ptr(const struct udevice *dev); /** * dev_read_addr_pci() - Read an address and handle PCI address translation @@ -266,7 +269,7 @@ void *dev_read_addr_ptr(struct udevice *dev); * @dev: Device to read from * @return address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_pci(struct udevice *dev); +fdt_addr_t dev_read_addr_pci(const struct udevice *dev); /** * dev_remap_addr() - Get the reg property of a device as a @@ -276,7 +279,7 @@ fdt_addr_t dev_read_addr_pci(struct udevice *dev); * * @return pointer or NULL if not found */ -void *dev_remap_addr(struct udevice *dev); +void *dev_remap_addr(const struct udevice *dev); /** * dev_read_addr_size() - get address and size from a device property @@ -289,8 +292,8 @@ void *dev_remap_addr(struct udevice *dev); * @sizep: place to put size value (on success) * @return address value, or FDT_ADDR_T_NONE on error */ -fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, - fdt_size_t *sizep); +fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname, + fdt_size_t *sizep); /** * dev_read_name() - get the name of a device's node @@ -298,7 +301,7 @@ fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, * @dev: Device to read from * @return name of node */ -const char *dev_read_name(struct udevice *dev); +const char *dev_read_name(const struct udevice *dev); /** * dev_read_stringlist_search() - find string in a string list and return index @@ -318,8 +321,8 @@ const char *dev_read_name(struct udevice *dev); * -ENODATA if the property is not found * -EINVAL on some other error */ -int dev_read_stringlist_search(struct udevice *dev, const char *property, - const char *string); +int dev_read_stringlist_search(const struct udevice *dev, const char *property, + const char *string); /** * dev_read_string_index() - obtain an indexed string from a string list @@ -332,8 +335,8 @@ int dev_read_stringlist_search(struct udevice *dev, const char *property, * @return: * length of string, if found or -ve error value if not found */ -int dev_read_string_index(struct udevice *dev, const char *propname, int index, - const char **outp); +int dev_read_string_index(const struct udevice *dev, const char *propname, + int index, const char **outp); /** * dev_read_string_count() - find the number of strings in a string list @@ -343,7 +346,7 @@ int dev_read_string_index(struct udevice *dev, const char *propname, int index, * @return: * number of strings in the list, or -ve error value if not found */ -int dev_read_string_count(struct udevice *dev, const char *propname); +int dev_read_string_count(const struct udevice *dev, const char *propname); /** * dev_read_phandle_with_args() - Find a node pointed by phandle in a list * @@ -382,10 +385,9 @@ int dev_read_string_count(struct udevice *dev, const char *propname); * @cells_name could not be found, the arguments were truncated or there * were too many arguments. */ -int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name, int cell_count, - int index, - struct ofnode_phandle_args *out_args); +int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, + const char *cells_name, int cell_count, + int index, struct ofnode_phandle_args *out_args); /** * dev_count_phandle_with_args() - Return phandle number in a list @@ -402,8 +404,8 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, * errno value. */ -int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name); +int dev_count_phandle_with_args(const struct udevice *dev, + const char *list_name, const char *cells_name); /** * dev_read_addr_cells() - Get the number of address cells for a device's node @@ -414,7 +416,7 @@ int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, * @dev: device to check * @return number of address cells this node uses */ -int dev_read_addr_cells(struct udevice *dev); +int dev_read_addr_cells(const struct udevice *dev); /** * dev_read_size_cells() - Get the number of size cells for a device's node @@ -425,7 +427,7 @@ int dev_read_addr_cells(struct udevice *dev); * @dev: device to check * @return number of size cells this node uses */ -int dev_read_size_cells(struct udevice *dev); +int dev_read_size_cells(const struct udevice *dev); /** * dev_read_addr_cells() - Get the address cells property in a node @@ -435,7 +437,7 @@ int dev_read_size_cells(struct udevice *dev); * @dev: device to check * @return number of address cells this node uses */ -int dev_read_simple_addr_cells(struct udevice *dev); +int dev_read_simple_addr_cells(const struct udevice *dev); /** * dev_read_size_cells() - Get the size cells property in a node @@ -445,7 +447,7 @@ int dev_read_simple_addr_cells(struct udevice *dev); * @dev: device to check * @return number of size cells this node uses */ -int dev_read_simple_size_cells(struct udevice *dev); +int dev_read_simple_size_cells(const struct udevice *dev); /** * dev_read_phandle() - Get the phandle from a device @@ -453,7 +455,7 @@ int dev_read_simple_size_cells(struct udevice *dev); * @dev: device to check * @return phandle (1 or greater), or 0 if no phandle or other error */ -int dev_read_phandle(struct udevice *dev); +int dev_read_phandle(const struct udevice *dev); /** * dev_read_prop()- - read a property from a device's node @@ -463,7 +465,8 @@ int dev_read_phandle(struct udevice *dev); * @lenp: place to put length on success * @return pointer to property, or NULL if not found */ -const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); +const void *dev_read_prop(const struct udevice *dev, const char *propname, + int *lenp); /** * dev_read_alias_seq() - Get the alias sequence number of a node @@ -476,7 +479,7 @@ const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); * @devnump: set to the sequence number if one is found * @return 0 if a sequence was found, -ve if not */ -int dev_read_alias_seq(struct udevice *dev, int *devnump); +int dev_read_alias_seq(const struct udevice *dev, int *devnump); /** * dev_read_u32_array() - Find and read an array of 32 bit integers @@ -494,7 +497,7 @@ int dev_read_alias_seq(struct udevice *dev, int *devnump); * property does not have a value, and -EOVERFLOW if the property data isn't * large enough. */ -int dev_read_u32_array(struct udevice *dev, const char *propname, +int dev_read_u32_array(const struct udevice *dev, const char *propname, u32 *out_values, size_t sz); /** @@ -504,7 +507,7 @@ int dev_read_u32_array(struct udevice *dev, const char *propname, * @return reference to the first subnode (which can be invalid if the device's * node has no subnodes) */ -ofnode dev_read_first_subnode(struct udevice *dev); +ofnode dev_read_first_subnode(const struct udevice *dev); /** * ofnode_next_subnode() - find the next sibling of a subnode @@ -529,8 +532,8 @@ ofnode dev_read_next_subnode(ofnode node); * @return pointer to byte array if found, or NULL if the property is not * found or there is not enough data */ -const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, - size_t sz); +const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, + const char *propname, size_t sz); /** * dev_read_enabled() - check whether a node is enabled @@ -543,7 +546,7 @@ const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, * @dev: device to examine * @return integer value 0 (not enabled) or 1 (enabled) */ -int dev_read_enabled(struct udevice *dev); +int dev_read_enabled(const struct udevice *dev); /** * dev_read_resource() - obtain an indexed resource from a device. @@ -553,7 +556,8 @@ int dev_read_enabled(struct udevice *dev); * @res returns the resource * @return 0 if ok, negative on error */ -int dev_read_resource(struct udevice *dev, uint index, struct resource *res); +int dev_read_resource(const struct udevice *dev, uint index, + struct resource *res); /** * dev_read_resource_byname() - obtain a named resource from a device. @@ -563,7 +567,7 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res); * @res: returns the resource * @return 0 if ok, negative on error */ -int dev_read_resource_byname(struct udevice *dev, const char *name, +int dev_read_resource_byname(const struct udevice *dev, const char *name, struct resource *res); /** @@ -577,7 +581,7 @@ int dev_read_resource_byname(struct udevice *dev, const char *name, * @in_addr: pointer to the address to translate * @return the translated address; OF_BAD_ADDR on error */ -u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); +u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr); /** * dev_translate_dma_address() - Translate a device-tree DMA address @@ -590,7 +594,8 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); * @in_addr: pointer to the DMA address to translate * @return the translated DMA address; OF_BAD_ADDR on error */ -u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr); +u64 dev_translate_dma_address(const struct udevice *dev, + const fdt32_t *in_addr); /** * dev_read_alias_highest_id - Get highest alias id for the given stem @@ -604,31 +609,31 @@ int dev_read_alias_highest_id(const char *stem); #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ -static inline int dev_read_u32(struct udevice *dev, +static inline int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp) { return ofnode_read_u32(dev_ofnode(dev), propname, outp); } -static inline int dev_read_u32_default(struct udevice *dev, +static inline int dev_read_u32_default(const struct udevice *dev, const char *propname, int def) { return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } -static inline int dev_read_s32(struct udevice *dev, +static inline int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp) { return ofnode_read_s32(dev_ofnode(dev), propname, outp); } -static inline int dev_read_s32_default(struct udevice *dev, +static inline int dev_read_s32_default(const struct udevice *dev, const char *propname, int def) { return ofnode_read_s32_default(dev_ofnode(dev), propname, def); } -static inline int dev_read_u32u(struct udevice *dev, +static inline int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp) { u32 val; @@ -642,128 +647,131 @@ static inline int dev_read_u32u(struct udevice *dev, return 0; } -static inline int dev_read_u64(struct udevice *dev, +static inline int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp) { return ofnode_read_u64(dev_ofnode(dev), propname, outp); } -static inline u64 dev_read_u64_default(struct udevice *dev, +static inline u64 dev_read_u64_default(const struct udevice *dev, const char *propname, u64 def) { return ofnode_read_u64_default(dev_ofnode(dev), propname, def); } -static inline const char *dev_read_string(struct udevice *dev, +static inline const char *dev_read_string(const struct udevice *dev, const char *propname) { return ofnode_read_string(dev_ofnode(dev), propname); } -static inline bool dev_read_bool(struct udevice *dev, const char *propname) +static inline bool dev_read_bool(const struct udevice *dev, + const char *propname) { return ofnode_read_bool(dev_ofnode(dev), propname); } -static inline ofnode dev_read_subnode(struct udevice *dev, +static inline ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name) { return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); } -static inline int dev_read_size(struct udevice *dev, const char *propname) +static inline int dev_read_size(const struct udevice *dev, const char *propname) { return ofnode_read_size(dev_ofnode(dev), propname); } -static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) +static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev, + int index) { return devfdt_get_addr_index(dev, index); } -static inline fdt_addr_t dev_read_addr_size_index(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, fdt_size_t *size) { return devfdt_get_addr_size_index(dev, index, size); } -static inline fdt_addr_t dev_read_addr_name(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) { return devfdt_get_addr_name(dev, name); } -static inline fdt_addr_t dev_read_addr_size_name(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, fdt_size_t *size) { return devfdt_get_addr_size_name(dev, name, size); } -static inline fdt_addr_t dev_read_addr(struct udevice *dev) +static inline fdt_addr_t dev_read_addr(const struct udevice *dev) { return devfdt_get_addr(dev); } -static inline void *dev_read_addr_ptr(struct udevice *dev) +static inline void *dev_read_addr_ptr(const struct udevice *dev) { return devfdt_get_addr_ptr(dev); } -static inline fdt_addr_t dev_read_addr_pci(struct udevice *dev) +static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev) { return devfdt_get_addr_pci(dev); } -static inline void *dev_remap_addr(struct udevice *dev) +static inline void *dev_remap_addr(const struct udevice *dev) { return devfdt_remap_addr(dev); } -static inline void *dev_remap_addr_index(struct udevice *dev, int index) +static inline void *dev_remap_addr_index(const struct udevice *dev, int index) { return devfdt_remap_addr_index(dev, index); } -static inline void *dev_remap_addr_name(struct udevice *dev, const char *name) +static inline void *dev_remap_addr_name(const struct udevice *dev, + const char *name) { return devfdt_remap_addr_name(dev, name); } -static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, +static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname, fdt_size_t *sizep) { return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); } -static inline const char *dev_read_name(struct udevice *dev) +static inline const char *dev_read_name(const struct udevice *dev) { return ofnode_get_name(dev_ofnode(dev)); } -static inline int dev_read_stringlist_search(struct udevice *dev, +static inline int dev_read_stringlist_search(const struct udevice *dev, const char *propname, const char *string) { return ofnode_stringlist_search(dev_ofnode(dev), propname, string); } -static inline int dev_read_string_index(struct udevice *dev, +static inline int dev_read_string_index(const struct udevice *dev, const char *propname, int index, const char **outp) { return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); } -static inline int dev_read_string_count(struct udevice *dev, +static inline int dev_read_string_count(const struct udevice *dev, const char *propname) { return ofnode_read_string_count(dev_ofnode(dev), propname); } -static inline int dev_read_phandle_with_args(struct udevice *dev, +static inline int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args) { @@ -772,59 +780,60 @@ static inline int dev_read_phandle_with_args(struct udevice *dev, out_args); } -static inline int dev_count_phandle_with_args(struct udevice *dev, +static inline int dev_count_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name) { return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, cells_name); } -static inline int dev_read_addr_cells(struct udevice *dev) +static inline int dev_read_addr_cells(const struct udevice *dev) { /* NOTE: this call should walk up the parent stack */ return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_size_cells(struct udevice *dev) +static inline int dev_read_size_cells(const struct udevice *dev) { /* NOTE: this call should walk up the parent stack */ return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_simple_addr_cells(struct udevice *dev) +static inline int dev_read_simple_addr_cells(const struct udevice *dev) { return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_simple_size_cells(struct udevice *dev) +static inline int dev_read_simple_size_cells(const struct udevice *dev) { return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_phandle(struct udevice *dev) +static inline int dev_read_phandle(const struct udevice *dev) { return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); } -static inline const void *dev_read_prop(struct udevice *dev, +static inline const void *dev_read_prop(const struct udevice *dev, const char *propname, int *lenp) { return ofnode_get_property(dev_ofnode(dev), propname, lenp); } -static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) +static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump) { return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, dev_of_offset(dev), devnump); } -static inline int dev_read_u32_array(struct udevice *dev, const char *propname, - u32 *out_values, size_t sz) +static inline int dev_read_u32_array(const struct udevice *dev, + const char *propname, u32 *out_values, + size_t sz) { return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); } -static inline ofnode dev_read_first_subnode(struct udevice *dev) +static inline ofnode dev_read_first_subnode(const struct udevice *dev) { return ofnode_first_subnode(dev_ofnode(dev)); } @@ -834,36 +843,38 @@ static inline ofnode dev_read_next_subnode(ofnode node) return ofnode_next_subnode(node); } -static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, +static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, const char *propname, size_t sz) { return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } -static inline int dev_read_enabled(struct udevice *dev) +static inline int dev_read_enabled(const struct udevice *dev) { return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev)); } -static inline int dev_read_resource(struct udevice *dev, uint index, +static inline int dev_read_resource(const struct udevice *dev, uint index, struct resource *res) { return ofnode_read_resource(dev_ofnode(dev), index, res); } -static inline int dev_read_resource_byname(struct udevice *dev, +static inline int dev_read_resource_byname(const struct udevice *dev, const char *name, struct resource *res) { return ofnode_read_resource_byname(dev_ofnode(dev), name, res); } -static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) +static inline u64 dev_translate_address(const struct udevice *dev, + const fdt32_t *in_addr) { return ofnode_translate_address(dev_ofnode(dev), in_addr); } -static inline u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr) +static inline u64 dev_translate_dma_address(const struct udevice *dev, + const fdt32_t *in_addr) { return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); } From patchwork Mon Jan 27 15:49:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229905 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=CeYOpTLf; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vNj6H6vz9sPJ for ; Tue, 28 Jan 2020 02:51:01 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F2C2181A27; Mon, 27 Jan 2020 16:50:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="CeYOpTLf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 448D881A1F; Mon, 27 Jan 2020 16:50:21 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 4B26881A11 for ; Mon, 27 Jan 2020 16:50:15 +0100 (CET) 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-io1-xd44.google.com with SMTP id k24so10500855ioc.4 for ; Mon, 27 Jan 2020 07:50:15 -0800 (PST) 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=98QWj6kIDd1/iMYAY0mVoe4cCUlJzddWZIgIFkbKSMI=; b=CeYOpTLfIgHr8IYxjW68zzepia/U4qAcgjsktb1snyGYt08YGpkSIe37lEp4B3FKN2 xjMEgpyZ+J9B2v1RMOXFy92y9dy6idxyUD7jodQkwcM8WZTN3ZQRHu6Cd2CzOprYCMTt NvS4TtApzO0G1YFzp2aZWN2XNst5/Kd5QplyM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=98QWj6kIDd1/iMYAY0mVoe4cCUlJzddWZIgIFkbKSMI=; b=K+4lZkLsOA8jMAQogvdDauEhsX9gnfAn9BpZKD6acHPyQYu4SRTz1ZhZzCtHuhywBz BXvq3QD1MtKekmn7qXv0r1alx3wjzK61zVG+GQ14az5fWztxjXevab1xYpNxi0i+zxug H/bYPathiW/kMpc6LT0LoUt1zJnIgWuVHKSXBl704SVjmQtitaZJWwO4RecQL0uQa3UB W1Q3XIExqpI2w+dV0FnL15QSeFDi3OC9aE1BwjdHR7IuPLvHOyYtYqrYGsH61MLM1UTF qWgj+TY3ukIKc/csa2FCWxhBS9AksDpE3BAMa9f2Ob4yHQqPdrmAMuJwZWChwwZm1foN 8Drg== X-Gm-Message-State: APjAAAXD64m6e3sc3W94efPzF9K6ytKZ79I3IcYNxFmSCniJMqzE/M/t FcaeH7MGyfP6fMwe6jszLCNStPqmZeY= X-Google-Smtp-Source: APXvYqzhICk7fR2sgXwIEBq/65RAY5WyBzuibwcXDWWExr2nnJhiQIFOi6OhxcyROMqShGpNEoCZyg== X-Received: by 2002:a02:ca59:: with SMTP id i25mr13424546jal.102.1580140213667; Mon, 27 Jan 2020 07:50:13 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:13 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 06/21] test: Add underscore prefix to macro parameters Date: Mon, 27 Jan 2020 08:49:41 -0700 Message-Id: <20200127084920.6.If6d0a8b5d09cac7de5b5ded8f9d5c5b6271f7893@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean If a test happens to use the same variable as the macro parameter the macro does not work as intended. Add an underscore to guard against this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- include/test/ut.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/test/ut.h b/include/test/ut.h index f616c202f3..c9fc9cc839 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -56,39 +56,39 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that two int expressions are equal */ #define ut_asserteq(expr1, expr2) { \ - unsigned int val1 = (expr1), val2 = (expr2); \ + unsigned int _val1 = (expr1), _val2 = (expr2); \ \ - if (val1 != val2) { \ + if (_val1 != _val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \ - "Expected %#x (%d), got %#x (%d)", val1, val1, \ - val2, val2); \ + "Expected %#x (%d), got %#x (%d)", \ + _val1, _val1, _val2, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that two string expressions are equal */ #define ut_asserteq_str(expr1, expr2) { \ - const char *val1 = (expr1), *val2 = (expr2); \ + const char *_val1 = (expr1), *_val2 = (expr2); \ \ - if (strcmp(val1, val2)) { \ + if (strcmp(_val1, _val2)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected \"%s\", got \"%s\"", val1, val2); \ + "Expected \"%s\", got \"%s\"", _val1, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that two memory areas are equal */ #define ut_asserteq_mem(expr1, expr2, len) { \ - const u8 *val1 = (u8 *)(expr1), *val2 = (u8 *)(expr2); \ + const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \ const uint __len = len; \ \ - if (memcmp(val1, val2, __len)) { \ + if (memcmp(_val1, _val2, __len)) { \ char __buf1[64 + 1] = "\0"; \ char __buf2[64 + 1] = "\0"; \ - bin2hex(__buf1, val1, min(__len, (uint)32)); \ - bin2hex(__buf2, val2, min(__len, (uint)32)); \ + bin2hex(__buf1, _val1, min(__len, (uint)32)); \ + bin2hex(__buf2, _val2, min(__len, (uint)32)); \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ "Expected \"%s\", got \"%s\"", \ @@ -99,33 +99,33 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that two pointers are equal */ #define ut_asserteq_ptr(expr1, expr2) { \ - const void *val1 = (expr1), *val2 = (expr2); \ + const void *_val1 = (expr1), *_val2 = (expr2); \ \ - if (val1 != val2) { \ + if (_val1 != _val2) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \ - "Expected %p, got %p", val1, val2); \ + "Expected %p, got %p", _val1, _val2); \ return CMD_RET_FAILURE; \ } \ } /* Assert that a pointer is NULL */ #define ut_assertnull(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (val != NULL) { \ + if (_val) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " != NULL", \ - "Expected NULL, got %p", val); \ + "Expected NULL, got %p", _val); \ return CMD_RET_FAILURE; \ } \ } /* Assert that a pointer is not NULL */ #define ut_assertnonnull(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (val == NULL) { \ + if (!_val) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \ "Expected non-null, got NULL"); \ @@ -135,13 +135,13 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that a pointer is not an error pointer */ #define ut_assertok_ptr(expr) { \ - const void *val = (expr); \ + const void *_val = (expr); \ \ - if (IS_ERR(val)) { \ + if (IS_ERR(_val)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \ "Expected pointer, got error %ld", \ - PTR_ERR(val)); \ + PTR_ERR(_val)); \ return CMD_RET_FAILURE; \ } \ } From patchwork Mon Jan 27 15:49:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229907 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=LbOLW0KH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vPC0lX7z9sPJ for ; Tue, 28 Jan 2020 02:51:27 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B5B5E81A28; Mon, 27 Jan 2020 16:50:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="LbOLW0KH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 704A681A1E; Mon, 27 Jan 2020 16:50:23 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 BDD0C81A17 for ; Mon, 27 Jan 2020 16:50:15 +0100 (CET) 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-io1-xd42.google.com with SMTP id n21so10488238ioo.10 for ; Mon, 27 Jan 2020 07:50:15 -0800 (PST) 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=6mL8Up0uiIvVAeBKXMjlpEd7uMoxLwTLJ18OexXPsKE=; b=LbOLW0KHMAgKhgvd4qN2Cj1g2U3CQVOY7yHLIjgrBEJh5Vh3UQxd2AqBrZuzSN145H 0xSJCqYK085jFvybf/elvOiEUbkEVz8VRjFDWTHwnUU9v1YioVmKfVwaS27rsfmvKYm3 RzA+uDH6p8iVAsOpPSO7C8yMiOPM5iqTqE5/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6mL8Up0uiIvVAeBKXMjlpEd7uMoxLwTLJ18OexXPsKE=; b=HhujBDbAZwwyL9E8pJAyfWtAonILUSZUf564JquV+bK4uiggvokU6bdAbDoH2WnQB0 +e7IZnKARO6eMZmlqlvkmd1sFgV/G5E6qVP5mS4dACax9bsX1pzj58xkdTueZxzWjvxQ 2ox+IYradPXoRzZ0na3r/fv6Z0yUu3/8YKm3t4t1OloqFGHzrJ8J6lhqpnHKPDWcQ/se YB2enpp0RYDxiBRpAZhqqwOtLgCGaN1uJKrTK8cf1/24jKKB3pOgxPa37KD4rtuNMudn 7ijCFU9gSDedRS9h7MO2tLYCbOGw+zzOg3rEa8LlUNfPR3b5sxohT2YRzaj3t1/TNsV5 hxlg== X-Gm-Message-State: APjAAAUnjcLKuX/ZhXyqrg6xMw1PzItPuBar3kx7tJQFB8d6ld94cyXi aOQ2mf583tAP9sWibS3+yCk/V0/NRw4= X-Google-Smtp-Source: APXvYqwMHS1NGHall3Ag0Wp8bAXOmK0yEGtYND/MaWqPFdcXIpaz5MsMv1ugZNeL9kV2Ge7eJI4Wrw== X-Received: by 2002:a05:6602:235b:: with SMTP id r27mr12976982iot.51.1580140214451; Mon, 27 Jan 2020 07:50:14 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 07/21] dm: core: Update comment for ofnode_get_chosen_node() Date: Mon, 27 Jan 2020 08:49:42 -0700 Message-Id: <20200127084920.7.If25281d45a0cd34637ee21792c9926a836078fcc@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean The current comment is a big vague and misleading. Rewrite it to state precisely what the function does. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- include/dm/ofnode.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 4282169706..62ba0c13ea 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -520,11 +520,14 @@ ofnode ofnode_path(const char *path); const char *ofnode_get_chosen_prop(const char *propname); /** - * ofnode_get_chosen_node() - get the chosen node + * ofnode_get_chosen_node() - get a referenced node from the chosen node * - * @return the chosen node if present, else ofnode_null() + * This looks up a named property in the chosen node and uses that as a path to + * look up a code. + * + * @return the referenced node if present, else ofnode_null() */ -ofnode ofnode_get_chosen_node(const char *name); +ofnode ofnode_get_chosen_node(const char *propname); struct display_timing; /** From patchwork Mon Jan 27 15:49:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229909 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=klO3pL6O; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vPk70NJz9sPJ for ; Tue, 28 Jan 2020 02:51:54 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E7EBE81A33; Mon, 27 Jan 2020 16:50:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="klO3pL6O"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3ECC981A26; Mon, 27 Jan 2020 16:50:26 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 D2A9181A0B for ; Mon, 27 Jan 2020 16:50:16 +0100 (CET) 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-io1-xd42.google.com with SMTP id e7so10485923iof.11 for ; Mon, 27 Jan 2020 07:50:16 -0800 (PST) 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=VxyaJbYGyaCXKxKjIrewFgz4C6sqgZc69JtBWjshuT0=; b=klO3pL6O9tvCS5o4Z3OWtyV2r4pbm5Q7j+zjr8+K0ySuEAAPMYkeLQw8quAxuIFpsc lIaOlT1Z1+8kOHV47ab2lGzyGbDeRuiZBIwCGyY8uV+/QzPuP4S2ekCrWw1BOZElCCia PN5JPKIuSuIaUzo94s3T/z1PN843Jd4ljAFQE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VxyaJbYGyaCXKxKjIrewFgz4C6sqgZc69JtBWjshuT0=; b=iizEN7FyalSzCB+KI1blE5TKPdRGQrRLoWgrCewQElmIHXEGctQwRAedpl8oH2M81B 4UBX5rHzjLo5r8bFOLFBMVryeevAXigW+WgMhN+c/kbJJx3ce716KcIt0p6Oa7yJEGeU 68TS2dyt/pWSfUcjj1NUhU3QqJiJjk39cKAss2azUSz2lYkMeVoH7tmL8lxS6nTFp9BV VV1pQJWL0/TycDshFItRfWYu1aCFx9Y7rrgRVdkjpnr50RC8xY8pV3VcM/OHi0Helwwb XR2BHNCorQa9zcG9X5VcjoqtAcUxCDVeuKBMt7qmI7kelN0sYB9BrPW6O0STKWep7RUI rSJA== X-Gm-Message-State: APjAAAUx5O/bJ5pzRymXIM+UaIV2hmdtBnMGx/5XRXUdorwzFHi3YKhC e2k86zecNDl25gVRp4A2H9+WbNyZmzE= X-Google-Smtp-Source: APXvYqxmVbl7Nj7TRPbW8pMfAyNE4gyLHkb82mikSqW9EE9Mj9LZny5VYiCE86k1K1oIF2/hqx1eDA== X-Received: by 2002:a05:6602:1ce:: with SMTP id w14mr12816291iot.275.1580140215261; Mon, 27 Jan 2020 07:50:15 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 08/21] dm: core: Rename ofnode_get_chosen_prop() Date: Mon, 27 Jan 2020 08:49:43 -0700 Message-Id: <20200127084920.8.I9f5ac53543976f8413d5879b751232b16efce5c3@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joe Hershberger , Pavel Herrmann , Ibai Erkiaga Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean This function is actually intended to read a string rather than a property. All of its current callers use it that way. Also there is no way to return the length of the property from this function. Rename it to better indicate its purpose, using ofnode_read as the prefix since this matches most other functions. Also add some tests which are missing for these functions. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 2 ++ .../puma_rk3399/puma-rk3399.c | 2 +- board/xilinx/common/board.c | 2 +- drivers/core/ofnode.c | 4 ++-- include/dm/ofnode.h | 9 ++++---- test/dm/ofnode.c | 21 +++++++++++++++++++ 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index e529c54d8d..a04afd4076 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -813,6 +813,8 @@ chosen { #address-cells = <1>; #size-cells = <1>; + setting = "sunrise ohoka"; + other-node = "/some-bus/c-test@5"; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>; diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c index 9887d20207..7ff4766947 100644 --- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c @@ -49,7 +49,7 @@ static void setup_iodomain(void) static int setup_boottargets(void) { const char *boot_device = - ofnode_get_chosen_prop("u-boot,spl-boot-device"); + ofnode_read_chosen_string("u-boot,spl-boot-device"); char *env_default, *env; if (!boot_device) { diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index ae5fe2729f..f87e2e9105 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -22,7 +22,7 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) return -ENODEV; debug("%s: Path to EEPROM %s\n", __func__, - ofnode_get_chosen_prop("xlnx,eeprom")); + ofnode_read_chosen_string("xlnx,eeprom")); ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); if (ret) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8f0eab2ca6..011b43bc02 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -419,7 +419,7 @@ ofnode ofnode_path(const char *path) return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path)); } -const char *ofnode_get_chosen_prop(const char *name) +const char *ofnode_read_chosen_string(const char *name) { ofnode chosen_node; @@ -432,7 +432,7 @@ ofnode ofnode_get_chosen_node(const char *name) { const char *prop; - prop = ofnode_get_chosen_prop(name); + prop = ofnode_read_chosen_string(name); if (!prop) return ofnode_null(); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 62ba0c13ea..9e76ae8407 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -510,14 +510,15 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name, ofnode ofnode_path(const char *path); /** - * ofnode_get_chosen_prop() - get the value of a chosen property + * ofnode_read_chosen_string() - get the string value of a chosen property * - * This looks for a property within the /chosen node and returns its value + * This looks for a property within the /chosen node and returns its value, + * checking that it is a valid nul-terminated string * * @propname: Property name to look for - * @return property value if found, else NULL + * @return string value if found, else NULL */ -const char *ofnode_get_chosen_prop(const char *propname); +const char *ofnode_read_chosen_string(const char *propname); /** * ofnode_get_chosen_node() - get a referenced node from the chosen node diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 745de50c7b..633a3a9e9a 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -58,3 +58,24 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) +{ + const char *str; + ofnode node; + + str = ofnode_read_chosen_string("setting"); + ut_assertnonnull(str); + ut_asserteq_str("sunrise ohoka", str); + ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting")); + + node = ofnode_get_chosen_node("other-node"); + ut_assert(ofnode_valid(node)); + ut_asserteq_str("c-test@5", ofnode_get_name(node)); + + node = ofnode_get_chosen_node("setting"); + ut_assert(!ofnode_valid(node)); + + return 0; +} +DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229910 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=bBs0R+49; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vPz1CDJz9sRW for ; Tue, 28 Jan 2020 02:52:07 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0CF2D81A39; Mon, 27 Jan 2020 16:51:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="bBs0R+49"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A9D9781A25; Mon, 27 Jan 2020 16:50:27 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (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 B3A2581A16 for ; Mon, 27 Jan 2020 16:50:17 +0100 (CET) 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-il1-x141.google.com with SMTP id t17so7809837ilm.13 for ; Mon, 27 Jan 2020 07:50:17 -0800 (PST) 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=vb24RRNUf7L4A/VNLP1DcIO4wvAECLTHXrRinV6p1/E=; b=bBs0R+49v5DqCR95NzqaRGv1RrYGJOEGfgc6m3H07GrHsGgTKkjDgcnyrkXyuiVRTf DHMpnvMCnM2mqufDYxat0M6Uzfq9x7hXflxuWKtRKsysTq6jSuRiDFe4bwCd7ltQC8+e g79MXlAvXwmxFZ/KMdzZOvLhJFtlRT/z+WgGk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vb24RRNUf7L4A/VNLP1DcIO4wvAECLTHXrRinV6p1/E=; b=aKuSnCXD6jhZ9Xjgk1/FFJljno6OHS+McMmeWyYkFltffQQuqH+EZuzDpnblmcLmDj JTR1Lj2zIQQIbrTuXPkEmfS5wcFGgtL4W0wpS0Z2XRjdTCRiUZKkuAlG64METh9tVCZE KUBAZPIfLgH7BMpJQRJ1FYyR3RLIg5JD/AzQUUsRzU+e0lqnW9OmEP0IuwjHSuU73p6E hNP3X3V9m6Qum4WWoHlA0qZ73n7358DURReIcF2bOmBOOYeGHJsG+Wkg3wqrBmpVksxv dR3bdfjpLmWSnPIT/IIbrE8qJTaPJoK3ZjnaR+pUj25G6PSXYAX53f8qYQc8lOiK2SDr 3PcA== X-Gm-Message-State: APjAAAWQ4O8KnwJrEKhxxurKB4JcJigD1DjO1WLef4o8sSNXvBysu3pu bGI2w3hMObLkrq0Q+6UBASoci+D9wz4= X-Google-Smtp-Source: APXvYqzivqAqRqMteMa41RNNKb2ZNPRY0h3NbYwT1At+xHSMT2dJQ6moHea5aneCjI4pSWUPGyqLNA== X-Received: by 2002:a92:5855:: with SMTP id m82mr15185573ilb.302.1580140216104; Mon, 27 Jan 2020 07:50:16 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:15 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 09/21] dm: core: Add ofnode_read_prop() Date: Mon, 27 Jan 2020 08:49:44 -0700 Message-Id: <20200127084920.9.Ib8a81e6304c5ed5ecb2149f2826a1c00cc4f5270@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Add a new function to read a property that supports reading the length as well. Reimplement ofnode_read_string() using it and fix its comment. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 31 ++++++++++++++++++++++++------- include/dm/ofnode.h | 13 ++++++++++++- test/dm/ofnode.c | 26 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 011b43bc02..eebc5a7dce 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -101,30 +101,47 @@ bool ofnode_read_bool(ofnode node, const char *propname) return prop ? true : false; } -const char *ofnode_read_string(ofnode node, const char *propname) +const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep) { - const char *str = NULL; - int len = -1; + const char *val = NULL; + int len; assert(ofnode_valid(node)); debug("%s: %s: ", __func__, propname); if (ofnode_is_np(node)) { struct property *prop = of_find_property( - ofnode_to_np(node), propname, NULL); + ofnode_to_np(node), propname, &len); if (prop) { - str = prop->value; + val = prop->value; len = prop->length; } } else { - str = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), + val = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname, &len); } - if (!str) { + if (!val) { debug("\n"); + if (sizep) + *sizep = -FDT_ERR_NOTFOUND; return NULL; } + if (sizep) + *sizep = len; + + return val; +} + +const char *ofnode_read_string(ofnode node, const char *propname) +{ + const char *str; + int len; + + str = ofnode_read_prop(node, propname, &len); + if (!str) + return NULL; + if (strnlen(str, len) >= len) { debug("\n"); return NULL; diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 9e76ae8407..8007483680 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -256,10 +256,21 @@ int ofnode_read_u64(ofnode node, const char *propname, u64 *outp); */ u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def); +/** + * ofnode_read_prop() - Read a property from a node + * + * @node: valid node reference to read property from + * @propname: name of the property to read + * @sizep: if non-NULL, returns the size of the property, or an error code + if not found + * @return property value, or NULL if there is no such property + */ +const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep); + /** * ofnode_read_string() - Read a string from a property * - * @ref: valid node reference to read property from + * @node: valid node reference to read property from * @propname: name of the property to read * @return string from property value, or NULL if there is no such property */ diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 633a3a9e9a..f1e4ed75db 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -59,6 +59,32 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +static int dm_test_ofnode_read(struct unit_test_state *uts) +{ + const u32 *val; + ofnode node; + int size; + + node = ofnode_path("/a-test"); + ut_assert(ofnode_valid(node)); + + val = ofnode_read_prop(node, "int-value", &size); + ut_assertnonnull(val); + ut_asserteq(4, size); + ut_asserteq(1234, fdt32_to_cpu(val[0])); + + val = ofnode_read_prop(node, "missing", &size); + ut_assertnull(val); + ut_asserteq(-FDT_ERR_NOTFOUND, size); + + /* Check it works without a size parameter */ + val = ofnode_read_prop(node, "missing", NULL); + ut_assertnull(val); + + return 0; +} +DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; From patchwork Mon Jan 27 15:49:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229912 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=L5C5SHR1; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vQQ6937z9sPJ for ; Tue, 28 Jan 2020 02:52:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1753881A37; Mon, 27 Jan 2020 16:51:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="L5C5SHR1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB8FB81A14; Mon, 27 Jan 2020 16:50:28 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (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 5563181A14 for ; Mon, 27 Jan 2020 16:50:18 +0100 (CET) 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-il1-x141.google.com with SMTP id i7so4657241ilr.7 for ; Mon, 27 Jan 2020 07:50:18 -0800 (PST) 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=6kfk6PHvUYKgX7CIpIlf33sMzMQVIdjNPk4MDgEtgt4=; b=L5C5SHR1c+R4rg+VnI8cvG+YhjAUNxuTEXyjMs4sYXIxVjxTaoL25gzMD5/iLtonLN M0814Y5CVA7JY7Zz4wryfphnNvH34l//6ewvA9bypVB93cOD35zv9tX28CG3VwTo6VCI 3FMPDWgXE96aU4ZUscM1kwYoCQnY6UOhWYEEk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6kfk6PHvUYKgX7CIpIlf33sMzMQVIdjNPk4MDgEtgt4=; b=nivrcrieTx/gy4JS9xI5/4Pi7prqb4vj7P3W+43h60l47Rm4c2kSBB8bZBwMyiCOQt Lq3DZnjUsxrr67HMdcv1dgVJS6ZpoW1hM8enXnwf9u/39n8fPQFbEpF0GUctJZwn944j +J2z+85h+6YeQiT3dKfwxg7jQotEWxsZS0tP/aY9o06tShYFrLxxSkT/QV3cueevFO9a o16f2Vq4BfLj9XjFaDyj07xfMLQ0v49WVXCKNRMnSVTebkhp4LXAKW5SD22ADfre3ykQ 0rdC3z0u+gG5hrxs8A6Fz3pzsEcsDBT/am5Pl+snEX6hqJWb7jVvdW6tnUL5OSY/eNjz Ti/w== X-Gm-Message-State: APjAAAWhoSKjnNG5LOq/C+vHtUExe/XIkForbREwKpPLtMLFq9nR3Wig E2IbNOb6ZUNO5ZcswIbAd/qV3JbENbM= X-Google-Smtp-Source: APXvYqwTAgganLjmECOWldNq7wdPuFX/WuEMeWf7evXXPJFi5otV9vdQvTX0Rzqw+zgbYdvIAYspHQ== X-Received: by 2002:a92:d18a:: with SMTP id z10mr16150513ilz.48.1580140216866; Mon, 27 Jan 2020 07:50:16 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:16 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 10/21] dm: core: Reimplement ofnode_read_size() Date: Mon, 27 Jan 2020 08:49:45 -0700 Message-Id: <20200127084920.10.I1dc4de977a1773af3abaccb48ffa7fa4882221e7@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Now that we have ofnode_read_prop() we can rewrite this function using that one, reducing the amount of duplicated code. Update ofnode_read_size() and move it up next to the other similar functions. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index eebc5a7dce..4fc29a7c43 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -151,6 +151,16 @@ const char *ofnode_read_string(ofnode node, const char *propname) return str; } +int ofnode_read_size(ofnode node, const char *propname) +{ + int len; + + if (!ofnode_read_prop(node, propname, &len)) + return -EINVAL; + + return len; +} + ofnode ofnode_find_subnode(ofnode node, const char *subnode_name) { ofnode subnode; @@ -253,25 +263,6 @@ ofnode ofnode_get_by_phandle(uint phandle) return node; } -int ofnode_read_size(ofnode node, const char *propname) -{ - int len; - - if (ofnode_is_np(node)) { - struct property *prop = of_find_property( - ofnode_to_np(node), propname, NULL); - - if (prop) - return prop->length; - } else { - if (fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname, - &len)) - return len; - } - - return -EINVAL; -} - fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size) { int na, ns; From patchwork Mon Jan 27 15:49:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229911 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=oZJp3bHZ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vQC0SKPz9sPJ for ; Tue, 28 Jan 2020 02:52:18 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6E90881A1C; Mon, 27 Jan 2020 16:51:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="oZJp3bHZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4C30D81A2B; Mon, 27 Jan 2020 16:50:27 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 1557381A19 for ; Mon, 27 Jan 2020 16:50:18 +0100 (CET) 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-io1-xd44.google.com with SMTP id z193so10522288iof.1 for ; Mon, 27 Jan 2020 07:50:18 -0800 (PST) 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=Xb2LRSKj8dMdTUDFhxjkCAYYGzTXNEek3iexi9tqxu0=; b=oZJp3bHZCv3TDoDRSO56LqmQxJx/UwUf17DWkOemCWZzBVXaxi9nn4raX1kUw/fH0f +ufAFtCZ/jTioHdZmFFO2nKvajEFGvn+R7vspi+p/PTFo4FpbKjZaVNRLKaU+UB0bnKP Xj+3bh6k7sqkjVCm/3Ky4H6IpVAaYPh2rP908= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xb2LRSKj8dMdTUDFhxjkCAYYGzTXNEek3iexi9tqxu0=; b=BblkT5tvdbWvx2AsSq7H+IJl5L+pIZhGdtLH1H4TXiP4H9FwdPsGpU3wvwYOcu+30+ 59BjBbaslFb0+igVKCxCvT4rkkoAXlE0pPscjiCbDm8sFu1hHsbK0i0RacmHZ8qVCYeL 6ci5piP9cU+K2N+sUi2Ok5WBMKmJ2xT+3bGxtTt+aUvpujgsESjKyx33Kc3LMMiGcx3U 2b6DV5GpdmmN0u7FddEM3rbg2RTwbCQ5DmrvjqXuST+bZ0VuCpKeGBebyz8DUhZqfMO1 RZpMnXhkMxlacTKXYwsGjoBH/UOiBQDamj5qYGZLIyEgmDIQL22K03QTMHkmrQ0mCGJX o8iw== X-Gm-Message-State: APjAAAW2fCiZko1b2b6wxxaOwli8s3z9gLAGQx/upzRtoJ5sywQn1IhX ZzlJHLBqw0eOFPi8sBCljzqw3/Nqk3s= X-Google-Smtp-Source: APXvYqx+9IkOiN49TbytYkNmf24+KOU96y/WynSHC/bRJ8Z1CC4Lqdikaib0p9FMEDzdsWnOb3QQCQ== X-Received: by 2002:a02:cd31:: with SMTP id h17mr13174590jaq.94.1580140217585; Mon, 27 Jan 2020 07:50:17 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:17 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 11/21] dm: core: Add ofnode_get_chosen_prop() Date: Mon, 27 Jan 2020 08:49:46 -0700 Message-Id: <20200127084920.11.I632d75f01fd709293b43d85b077a4ed2e4dc4e58@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean Add a function to read a property from the chosen node, providing access to its length. Update ofnode_get_chosen_string() to make use of it. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 1 + drivers/core/ofnode.c | 11 ++++++++--- include/dm/ofnode.h | 12 ++++++++++++ test/dm/ofnode.c | 8 ++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index a04afd4076..347ea79077 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -815,6 +815,7 @@ #size-cells = <1>; setting = "sunrise ohoka"; other-node = "/some-bus/c-test@5"; + int-values = <0x1937 72993>; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 4fc29a7c43..f55ef15cee 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -427,20 +427,25 @@ ofnode ofnode_path(const char *path) return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path)); } -const char *ofnode_read_chosen_string(const char *name) +const void *ofnode_read_chosen_prop(const char *propname, int *sizep) { ofnode chosen_node; chosen_node = ofnode_path("/chosen"); - return ofnode_read_string(chosen_node, name); + return ofnode_read_prop(chosen_node, propname, sizep); +} + +const char *ofnode_read_chosen_string(const char *propname) +{ + return ofnode_read_chosen_prop(propname, NULL); } ofnode ofnode_get_chosen_node(const char *name) { const char *prop; - prop = ofnode_read_chosen_string(name); + prop = ofnode_read_chosen_prop(name, NULL); if (!prop) return ofnode_null(); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 8007483680..b5a50e8849 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -520,6 +520,18 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name, */ ofnode ofnode_path(const char *path); +/** + * ofnode_read_chosen_prop() - get the value of a chosen property + * + * This looks for a property within the /chosen node and returns its value + * + * @propname: Property name to look for + * @sizep: Returns size of property, or FDT_ERR_... error code if function + * returns NULL + * @return property value if found, else NULL + */ +const void *ofnode_read_chosen_prop(const char *propname, int *sizep); + /** * ofnode_read_chosen_string() - get the string value of a chosen property * diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index f1e4ed75db..1c49eaf38b 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -88,7 +88,9 @@ DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; + const u32 *val; ofnode node; + int size; str = ofnode_read_chosen_string("setting"); ut_assertnonnull(str); @@ -102,6 +104,12 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) node = ofnode_get_chosen_node("setting"); ut_assert(!ofnode_valid(node)); + val = ofnode_read_chosen_prop("int-values", &size); + ut_assertnonnull(val); + ut_asserteq(8, size); + ut_asserteq(0x1937, fdt32_to_cpu(val[0])); + ut_asserteq(72993, fdt32_to_cpu(val[1])); + return 0; } DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229913 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=QwD/c73e; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vQd2CCTz9sRW for ; Tue, 28 Jan 2020 02:52:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 429EA81A40; Mon, 27 Jan 2020 16:51:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QwD/c73e"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B800381A19; Mon, 27 Jan 2020 16:50:29 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 04C2E81A12 for ; Mon, 27 Jan 2020 16:50:19 +0100 (CET) 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-il1-x142.google.com with SMTP id o13so7199662ilg.10 for ; Mon, 27 Jan 2020 07:50:19 -0800 (PST) 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=MGgeS11v/qVgX0N7uykm6Td+m0ipmCeYuH1mfewfaJU=; b=QwD/c73evElQe2xH63u4Ery41qi3Y94AiYI/egv84isTkQf0EYc0FYBzHrAbFlmF7C FjaKAmgm6SHvxnaSIwX6rjX6HwTuJepG5w5YHfXLIsL5CwbTBXDBbFZwX2CGLj2GOalM e0DceztV7NMjt1dkUmuTywDAFl1RnuSMwUFvM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MGgeS11v/qVgX0N7uykm6Td+m0ipmCeYuH1mfewfaJU=; b=KXQEUcUUqKm8rdXZKDcmpA2Qpdjo4PEkHbtLCWYg3S3BfeKHxYkjTqp952hroIy/wb 6ocBCHKIz2M+dEwn8GPe07pGwO1NoRAwICzvpaEGCK1DHHCVUaK8RT7m7YGrfkOzIslB rAo5c14PpKb4My+qJNWi2RmmNqOZUnh/eBzBNXifhjm3ivx/gJfpdZ89KGAu5kzqoRcZ JW0tM8Cb69fqbdrsH23swJYZ7v4968E2QH7r5hvYDW1QCrHrPmfqBZAs2tkvVCzsCnTL 5niOXvTSQft+B2TcYsMjAIFWYszVy/NDkzpALO3PLGNQjyWwZ3mNWXRKidMFR156t1yr ejjA== X-Gm-Message-State: APjAAAVnV6MpheF5KqXwxchWmcNdAwQzHRNlz0vqDYBJROYwRijefb7h FQljpaT88jusAATp/vmUjsDtopranIc= X-Google-Smtp-Source: APXvYqypNZ/wmrZyRfQBe10tNZwWVuSxVc1rSGUnio9ArFWXxCzVsBU6L7za5aNd4psZvuKCDxaA7A== X-Received: by 2002:a92:ce85:: with SMTP id r5mr15915440ilo.301.1580140218361; Mon, 27 Jan 2020 07:50:18 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:18 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 12/21] dm: core: Add a way to read platdata for all child devices Date: Mon, 27 Jan 2020 08:49:47 -0700 Message-Id: <20200127084920.12.I68491432ec9983eb6b1af18bb8400ccddbb7709d@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean When generating ACPI tables we need to make sure that all devices have read their platform data, so that they can generate the tables correctly. Rather than adding this code in ACPI, create a core function to handle it. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/device.c | 36 ++++++++++++++++++++++++++++++++++++ include/dm/device.h | 42 ++++++++++++++++++++++++++++++++++++++++++ include/dm/read.h | 3 ++- test/dm/test-fdt.c | 19 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index b7f59fcde3..c948d8dbbc 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -792,6 +792,42 @@ int device_find_child_by_name(const struct udevice *parent, const char *name, return -ENODEV; } +int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp) +{ + struct udevice *dev; + int ret; + + device_find_first_child(parent, &dev); + if (!dev) + return -ENODEV; + + ret = device_ofdata_to_platdata(dev); + if (ret) + return ret; + + *devp = dev; + + return 0; +} + +int device_next_child_ofdata_err(struct udevice **devp) +{ + struct udevice *dev = *devp; + int ret; + + device_find_next_child(&dev); + if (!dev) + return -ENODEV; + + ret = device_ofdata_to_platdata(dev); + if (ret) + return ret; + + *devp = dev; + + return 0; +} + struct udevice *dev_get_parent(const struct udevice *child) { return child->parent; diff --git a/include/dm/device.h b/include/dm/device.h index 611fc2e197..2618952336 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -577,6 +577,31 @@ int device_find_first_child_by_uclass(const struct udevice *parent, int device_find_child_by_name(const struct udevice *parent, const char *name, struct udevice **devp); +/** + * device_first_child_ofdata_err() - Find the first child and reads its platdata + * + * The ofdata_to_platdata() method is called on the child before it is returned, + * but the child is not probed. + * + * @parent: Parent to check + * @devp: Returns child that was found, if any + * @return 0 on success, -ENODEV if no children, other -ve on error + */ +int device_first_child_ofdata_err(struct udevice *parent, + struct udevice **devp); + +/* + * device_next_child_ofdata_err() - Find the next child and read its platdata + * + * The ofdata_to_platdata() method is called on the child before it is returned, + * but the child is not probed. + * + * @devp: On entry, points to the previous child; on exit returns the child that + * was found, if any + * @return 0 on success, -ENODEV if no children, other -ve on error + */ +int device_next_child_ofdata_err(struct udevice **devp); + /** * device_has_children() - check if a device has any children * @@ -706,6 +731,23 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev) #define device_foreach_child(pos, parent) \ list_for_each_entry(pos, &parent->child_head, sibling_node) +/** + * device_foreach_child_ofdata_to_platdata() - iterate through children + * + * This stops when it gets an error, with @pos set to the device that failed to + * read ofdata. + + * This creates a for() loop which works through the available children of + * a device in order from start to end. Device ofdata is read by calling + * device_ofdata_to_platdata() on each one. The devices are not probed. + * + * @pos: struct udevice * for the current device + * @parent: parent device to scan + */ +#define device_foreach_child_ofdata_to_platdata(pos, parent) \ + for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \ + _ret = device_next_child_ofdata_err(&dev)) + /** * dm_scan_fdt_dev() - Bind child device in a the device tree * diff --git a/include/dm/read.h b/include/dm/read.h index 92a7328fc8..da8c7f25e7 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -844,7 +844,8 @@ static inline ofnode dev_read_next_subnode(ofnode node) } static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, - const char *propname, size_t sz) + const char *propname, + size_t sz) { return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index d59c449ce0..8fe4425b21 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -872,3 +872,22 @@ static int dm_test_read_int(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_first_child_ofdata_err(), etc. */ +static int dm_test_child_ofdata(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + int count; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); + count = 0; + device_foreach_child_ofdata_to_platdata(dev, bus) { + ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + count++; + } + ut_asserteq(3, count); + + return 0; +} +DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229914 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=hjR1XRax; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vQq4XyVz9sPJ for ; Tue, 28 Jan 2020 02:52:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A133D81A44; Mon, 27 Jan 2020 16:51:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hjR1XRax"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AF91981A32; Mon, 27 Jan 2020 16:50:31 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 9CBD681A23 for ; Mon, 27 Jan 2020 16:50:20 +0100 (CET) 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-il1-x143.google.com with SMTP id b15so7845194iln.3 for ; Mon, 27 Jan 2020 07:50:20 -0800 (PST) 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=fcox4/rXqttmW3X/fAycOWkSJwm+H3N2nfNSHRN3n3o=; b=hjR1XRaxVsmj07ik1PnZGRp/dPKVnsejQLStqBAe+SOq8B29yaTGWhCJvrkzTYqil5 4DNbFHcsjZmTygHB/drBLE4HxmiIcF/gAR9fba1YOKDnmHnVWyVJCS4U9XvhYdkzzfsY fzehCUK/ep/0U1mvLuc/dsBmjS6CP7JahIDBY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fcox4/rXqttmW3X/fAycOWkSJwm+H3N2nfNSHRN3n3o=; b=mwGqctjLs4vpB4gl9aYNYoJrV9I9VlV6/8QX24AmSMNI6kdbTneBV8VK4HaYb4W5nQ 2BuTwt40vvz8JKfiEV6OppRl+XTTKxgu7OM5PHGSQJKRnFadl5/AeTCTkApd27DXRmSa R2OSpgxvrxR8djFelLo3Uo3wF5U5xuiY2nUJ6rT6NGaxDbjaFM9Kfmu7hbDBsPMXglCj KPKOHGXuKtYRuvWcIG+158fsfuYPNaq8Hs/bhXjKlmu4vwteH2O5o3aWn8blq6VLHJ6x BP8jDFIB42h1ysFVlBOklq2OFWXNDEF6H6QFbFF49Evc16+3v2kuPSix9N3YyxH12LPK 4EEw== X-Gm-Message-State: APjAAAVYbSPMaYK473gAOQJkO0IkWAzUiFCPC9Nd0sOc5UgIyaHW1xUm PJUrftS7xn3SvQBCo6rtvEvjgmWkXjM= X-Google-Smtp-Source: APXvYqxxywHSFmHmoCQBoeeZbAlHBipiTS27zrdgtVBuJr6Or9efuxbqoqIAAeyXqW/zya0RkTyjTQ== X-Received: by 2002:a92:5d8d:: with SMTP id e13mr15072122ilg.285.1580140219154; Mon, 27 Jan 2020 07:50:19 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:18 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 13/21] dm: core: Add a way to iterate through children, probing each Date: Mon, 27 Jan 2020 08:49:48 -0700 Message-Id: <20200127084920.13.I307389a2de896b0eee9728fa4cb109f1b5379693@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean It is sometimes useful to process all children, making sure they are probed first. Add functions to help with this and a macro to make it more convenient. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/device.c | 22 ++++++++++++++++++++++ include/dm/device.h | 39 +++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 19 +++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index c948d8dbbc..89ea820d48 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -792,6 +792,28 @@ int device_find_child_by_name(const struct udevice *parent, const char *name, return -ENODEV; } +int device_first_child_err(struct udevice *parent, struct udevice **devp) +{ + struct udevice *dev; + + device_find_first_child(parent, &dev); + if (!dev) + return -ENODEV; + + return device_get_device_tail(dev, 0, devp); +} + +int device_next_child_err(struct udevice **devp) +{ + struct udevice *dev = *devp; + + device_find_next_child(&dev); + if (!dev) + return -ENODEV; + + return device_get_device_tail(dev, 0, devp); +} + int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp) { struct udevice *dev; diff --git a/include/dm/device.h b/include/dm/device.h index 2618952336..517ae7fc90 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -602,6 +602,28 @@ int device_first_child_ofdata_err(struct udevice *parent, */ int device_next_child_ofdata_err(struct udevice **devp); +/** + * device_first_child_err() - Get the first child of a device + * + * The device returned is probed if necessary, and ready for use + * + * @parent: Parent device to search + * @devp: Returns device found, if any + * @return 0 if found, -ENODEV if not, -ve error if device failed to probe + */ +int device_first_child_err(struct udevice *parent, struct udevice **devp); + +/** + * device_next_child_err() - Get the next child of a parent device + * + * The device returned is probed if necessary, and ready for use + * + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next sibling if no error occurred + * @return 0 if found, -ENODEV if not, -ve error if device failed to probe + */ +int device_next_child_err(struct udevice **devp); + /** * device_has_children() - check if a device has any children * @@ -748,6 +770,23 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev) for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \ _ret = device_next_child_ofdata_err(&dev)) +/** + * device_foreach_child_probe() - iterate through children, probing them + * + * This creates a for() loop which works through the available children of + * a device in order from start to end. Devices are probed if necessary, + * and ready for use. + * + * This stops when it gets an error, with @pos set to the device that failed to + * probe + * + * @pos: struct udevice * for the current device + * @parent: parent device to scan + */ +#define device_foreach_child_probe(pos, parent) \ + for (int _ret = device_first_child_err(parent, &dev); !_ret; \ + _ret = device_next_child_err(&dev)) + /** * dm_scan_fdt_dev() - Bind child device in a the device tree * diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 8fe4425b21..cd65e42a88 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -891,3 +891,22 @@ static int dm_test_child_ofdata(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_first_child_err(), etc. */ +static int dm_test_first_child_probe(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + int count; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); + count = 0; + device_foreach_child_probe(dev, bus) { + ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(dev->flags & DM_FLAG_ACTIVATED); + count++; + } + ut_asserteq(3, count); + + return 0; +} +DM_TEST(dm_test_first_child_probe, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Mon Jan 27 15:49:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229915 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=YgyzJRqz; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vR173Ymz9sPJ for ; Tue, 28 Jan 2020 02:53:01 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B0C0681A4F; Mon, 27 Jan 2020 16:51:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="YgyzJRqz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD53981A15; Mon, 27 Jan 2020 16:50:32 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 60DFD81A11 for ; Mon, 27 Jan 2020 16:50:21 +0100 (CET) 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-il1-x143.google.com with SMTP id f10so7845488ils.8 for ; Mon, 27 Jan 2020 07:50:21 -0800 (PST) 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=oxeyAs+lFtt697vsy0cMBz/cwXnE3PfHJJE37fH9Ib0=; b=YgyzJRqzk3UTUZ6gE8NIKm1BmCs+kejgtwjRBuBirXJXL4lfEPqXdNCeoZ7BRY0KeJ AvRsnVtXr9R7tGRdSajGDgrKdHTSaMKQBkaYHB7QSiO6tPzRajhvmtR8Ti14YPcqdOgB 0LPF3ijqXcXOoS/VY7dAyCbiPwJczTrpLn38E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oxeyAs+lFtt697vsy0cMBz/cwXnE3PfHJJE37fH9Ib0=; b=RiH/jxE2vyYyAcDUsyWqLX+Ygj2HBHDRoUTFgfSlt6s2tUpQe99mqiN9vWlz4XsfZT n77mKnuhZswURWpbfUqCTWGln670fkDab8beHXFXKTFAhVwAYZT1DWeEYKzo3lUZpj1U P4DTxLuPsKrhi+TVWZHj8cZoG4hsciJacLhXGiIATBpQE/rsQkm0c+Iuq+Q7Gwupo8Qn S7IMBUKAgpkDvDtBXD6/TD6RwfoxZjT7MHV3V1vB48SDl+tj/cJ5JRLr0rhDwxGEcjq2 LtrMXgWOD0+1L4DUcbJ1NhfHXi2GeJNSuBs69Mk9DS8qwGhhOxyTPLan/BERcqk20ngf P3QQ== X-Gm-Message-State: APjAAAVsJ9oJ8NORE7TdQgvNvv9zMdupInnEKos5ySw9P7V90s7LVAQC 0276b31mYuVYR4v6YtVsYgMEa6a6VFc= X-Google-Smtp-Source: APXvYqzJAJEIbgYgYa8S3tWv4+bGUe0k7UmgU/McHiS8ykrs9/7ewD1+0ofhWsyJ7bUx1SxQeBn+Qg== X-Received: by 2002:a92:3c86:: with SMTP id j6mr16136177ilf.104.1580140219868; Mon, 27 Jan 2020 07:50:19 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:19 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 14/21] dm: core: Drop uclass_find_next_free_req_seq() conditions Date: Mon, 27 Jan 2020 08:49:49 -0700 Message-Id: <20200127084920.14.Ib428956dc56e56ec5f488b4b4e16f4fa82bdb160@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Herrmann Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean These conditions are not needed and just reduce build coverage. Drop them. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/core/uclass.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index c520ef113a..cd6ee47146 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -271,9 +271,6 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name, return -ENODEV; } -#if !CONFIG_IS_ENABLED(OF_CONTROL) || \ - CONFIG_IS_ENABLED(OF_PLATDATA) || \ - CONFIG_IS_ENABLED(OF_PRIOR_STAGE) int uclass_find_next_free_req_seq(enum uclass_id id) { struct uclass *uc; @@ -295,7 +292,6 @@ int uclass_find_next_free_req_seq(enum uclass_id id) return max + 1; } -#endif int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) From patchwork Mon Jan 27 15:49:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229916 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=fldKOeZs; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vRF5xG8z9sPJ for ; Tue, 28 Jan 2020 02:53:13 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CBD3F81A4B; Mon, 27 Jan 2020 16:51:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="fldKOeZs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D820B81A25; Mon, 27 Jan 2020 16:50:31 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 1447B81A15 for ; Mon, 27 Jan 2020 16:50:21 +0100 (CET) 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-io1-xd42.google.com with SMTP id z193so10522467iof.1 for ; Mon, 27 Jan 2020 07:50:21 -0800 (PST) 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=6wp9p5zISzFgRIrsnrmdrKOXKYDo7Aj43RTtX3L2IDs=; b=fldKOeZsfxu/90p5DIzqgJ8FYCk5Wbl3Y1Urb8uXfZ1GakAMWHk1ps12oNp3YAF0Vx Ic9tN0sneqe9IYDrYwzjemwe/Cc7BOQb3mThvXyfqoD1+Ij7CfYaYpMeleLsPCZNH6DC sYiFOQEFK+ipDZIosD6e3RRjstLOOkAETwc2c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6wp9p5zISzFgRIrsnrmdrKOXKYDo7Aj43RTtX3L2IDs=; b=FIlOND8B52r7wswgArwDXnHT1dV8wqyh7c47e68UPGz+9skcyk8j61oaWfxxU8PBuE AvNbQ8RPz0K16A2zP8a/AwUScjiPgdUQYkX3e+L/tWYNpzFXgdBUIVesb996HZ1KvmWb ox1/jFrrRux45r3wcDiMSPiIME8dbxYoNHVcW+3sWkmfA1C5PBYL9vlyay2i8+xrOx69 yr+9A3nrTW/TgR0YX3Re7WVYQZelA7rCtP2ty4Q4oC33jIq1OyUrzwjCjVpmTe15IoL8 0OIYNzDnxJOvnJ8QfT+CHtVDNlFWX5kXLavvipPMCB0ook7xweqJDwSSLublOQydMRX4 3B7A== X-Gm-Message-State: APjAAAU+S62v8FSu86VKdYSHq2BKepee0C+pUbh1N8o5wd+dXag9TqaN 8QA/I3qu+nNCyYn0c5aBMo8lT8xy1/c= X-Google-Smtp-Source: APXvYqy9R9Y2x/TgrB5WfIM1bYxEJ/9RREHPPW+tKCOSGcqJvZnR29UOhQDxR8yp5tVCf/dPCOlrEg== X-Received: by 2002:a6b:760f:: with SMTP id g15mr12706554iom.56.1580140220647; Mon, 27 Jan 2020 07:50:20 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:20 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 15/21] bloblist: Add a new function to add or check size Date: Mon, 27 Jan 2020 08:49:50 -0700 Message-Id: <20200127084920.15.I54b288f82c19b6c8a3d350ab3a49f971cd19dce9@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean A common check is to see if a blob is present, create it if not and make sure that the size is large enough. Add a function to handle this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- common/bloblist.c | 15 +++++++++++++++ include/bloblist.h | 13 +++++++++++++ test/bloblist.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/common/bloblist.c b/common/bloblist.c index ccf5e4b6f6..0c87115e81 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -145,6 +145,21 @@ void *bloblist_ensure(uint tag, int size) return (void *)rec + rec->hdr_size; } +int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp) +{ + struct bloblist_rec *rec; + int ret; + + ret = bloblist_ensurerec(tag, &rec, *sizep); + if (ret == -ESPIPE) + *sizep = rec->size; + else if (ret) + return ret; + *blobp = (void *)rec + rec->hdr_size; + + return 0; +} + static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr) { struct bloblist_rec *rec; diff --git a/include/bloblist.h b/include/bloblist.h index 85144010ab..8c9ce98a3b 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -151,6 +151,19 @@ int bloblist_ensure_size(uint tag, int size, void **blobp); */ void *bloblist_ensure(uint tag, int size); +/** + * bloblist_ensure_size_ret() - Find or add a blob + * + * Find an existing blob, or add a new one if not found + * + * @tag: Tag to add (enum bloblist_tag_t) + * @sizep: Size of the blob to create; returns size of actual blob + * @blobp: Returns a pointer to blob on success + * @return 0 if OK, -ENOSPC if it is missing and could not be added due to lack + * of space + */ +int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp); + /** * bloblist_new() - Create a new, empty bloblist of a given size * diff --git a/test/bloblist.c b/test/bloblist.c index d0f7296e0d..c78b58ea29 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -24,6 +24,7 @@ enum { TEST_SIZE = 10, TEST_SIZE2 = 20, + TEST_SIZE_LARGE = 0xe0, TEST_ADDR = CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE = 0x100, @@ -97,6 +98,39 @@ static int bloblist_test_blob(struct unit_test_state *uts) } BLOBLIST_TEST(bloblist_test_blob, 0); +/* Check bloblist_ensure_size_ret() */ +static int bloblist_test_blob_ensure(struct unit_test_state *uts) +{ + void *data, *data2; + int size; + + /* At the start there should be no records */ + clear_bloblist(); + ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0)); + + /* Test with an empty bloblist */ + size = TEST_SIZE; + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); + ut_asserteq(TEST_SIZE, size); + + /* Check that we get the same thing again */ + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); + ut_asserteq(TEST_SIZE, size); + ut_asserteq_ptr(data, data2); + + /* Check that the size remains the same */ + size = TEST_SIZE2; + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); + ut_asserteq(TEST_SIZE, size); + + /* Check running out of space */ + size = TEST_SIZE_LARGE; + ut_asserteq(-ENOSPC, bloblist_ensure_size_ret(TEST_TAG2, &size, &data)); + + return 0; +} +BLOBLIST_TEST(bloblist_test_blob_ensure, 0); + static int bloblist_test_bad_blob(struct unit_test_state *uts) { struct bloblist_hdr *hdr; From patchwork Mon Jan 27 15:49:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229917 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=l93Vox0u; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vRS3Dk9z9sNx for ; Tue, 28 Jan 2020 02:53:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 415E181A53; Mon, 27 Jan 2020 16:51:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="l93Vox0u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5A12481A2A; Mon, 27 Jan 2020 16:50:32 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (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 B5A1A81A27 for ; Mon, 27 Jan 2020 16:50:22 +0100 (CET) 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-io1-xd43.google.com with SMTP id h8so10510896iob.2 for ; Mon, 27 Jan 2020 07:50:22 -0800 (PST) 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=NFk25ueCNTI5XCc4j/0E8H5fHUrVFEmIUkTr4EnRuBY=; b=l93Vox0uGDSUKihVY/2vIXoXGDYXsDZu94Maf3folG+SkKcbyWCDEHxuJlII8TXgk5 feIvgnVeYZtev0dIA+tv1+2OG8JrNDE0lJTlVLQhreOrCE5YxSJkZBsv7OtFfDndvGeg 2jkyoAfYLLwg1FC6cjXBtUHuUH/4FZFOFqdMw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NFk25ueCNTI5XCc4j/0E8H5fHUrVFEmIUkTr4EnRuBY=; b=LE73ngFsL4ex+p0baw/J7zraxq20CpwlfvVLDoBLNp+B8kJNRKnDlFLGUC4bWl+khk d7AaoFXHA6FpeZAJVrQn8rVXC0D0kNVO9plyQv67Eofekb+ggdp6l27nfWCLpJf2n1qk Bdnvo871tFgoYU2668FLwdj9ENlNAG5/wsiDF/cPg2J4x9QikON5zRW/YlMv9YDlBCDQ VVNTehocfRhaUcVCVdyh/BFB1Icv+cAUt1phzTiqVIIN11Qy/Dpr+TcIMshQrr/rFhah nk6wZ408otCa95RYcW6NVrRImCMgQXK+6pofFmnItwbq6OsGFN4klYOWeItkxy69r7AU wryQ== X-Gm-Message-State: APjAAAVBjsU5DcbcNmT/fXkLqpmprhQNBL6bcqhJWdg/p4e/lNhkwTsq CNE6rErt2+Qdk4Xz6BISiSBC+60JQ0k= X-Google-Smtp-Source: APXvYqyn/gPPTTU8IaW3tS3xOC/GEnSvrzxTlOlwCzpap2ogsUt6pjhSZfWu4qNxtgNO6cb4kHCkKQ== X-Received: by 2002:a5e:df46:: with SMTP id g6mr12970263ioq.240.1580140221284; Mon, 27 Jan 2020 07:50:21 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:21 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 16/21] bloblist: Tidy up a few comments and code-style nits Date: Mon, 27 Jan 2020 08:49:51 -0700 Message-Id: <20200127084920.16.If57a0ad7fb8aeef04ec034b19c95cd24b4fb9644@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean Add a messing error code to bloblist_new() and tidy up the line length in bloblist_addrec(). Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- common/bloblist.c | 5 ++--- include/bloblist.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/bloblist.c b/common/bloblist.c index 0c87115e81..e2b7cc62e0 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -59,11 +59,10 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) struct bloblist_rec *rec; int new_alloced; - new_alloced = hdr->alloced + sizeof(*rec) + - ALIGN(size, BLOBLIST_ALIGN); + new_alloced = hdr->alloced + sizeof(*rec) + ALIGN(size, BLOBLIST_ALIGN); if (new_alloced >= hdr->size) { log(LOGC_BLOBLIST, LOGL_ERR, - "Failed to allocate %x bytes size=%x, need size>=%x\n", + "Failed to allocate %x bytes size=%x, need size=%x\n", size, hdr->size, new_alloced); return log_msg_ret("bloblist add", -ENOSPC); } diff --git a/include/bloblist.h b/include/bloblist.h index 8c9ce98a3b..609ac421d6 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -183,7 +183,8 @@ int bloblist_new(ulong addr, uint size, uint flags); * @return 0 if OK, -ENOENT if the magic number doesn't match (indicating that * there problem is no bloblist at the given address), -EPROTONOSUPPORT * if the version does not match, -EIO if the checksum does not match, - * -EFBIG if the expected size does not match the detected size + * -EFBIG if the expected size does not match the detected size, -ENOSPC + * if the size is not large enough to hold the headers */ int bloblist_check(ulong addr, uint size); From patchwork Mon Jan 27 15:49:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229918 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=nqy6dVi8; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vRg2qrGz9sNx for ; Tue, 28 Jan 2020 02:53:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 388F581A59; Mon, 27 Jan 2020 16:51:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="nqy6dVi8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5DC2481A2B; Mon, 27 Jan 2020 16:50:34 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 7974581A10 for ; Mon, 27 Jan 2020 16:50:23 +0100 (CET) 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-io1-xd32.google.com with SMTP id z193so10522554iof.1 for ; Mon, 27 Jan 2020 07:50:23 -0800 (PST) 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=+QFKsubIF1XIMI5ZlwkuqXYmOTENsY38HLXn6DHwr8s=; b=nqy6dVi8K4nB1HJyS+XYWcZ36pu6BB22N9oyY/19E5UYiaTEjrwIsFrWeHds2qNeoh hvHBJ+k5JUNnFGhj3FT/ccNIWUufB0NU6VuZU2HY1hPdccjdnvCs5nJoqIWcl3RwQk7t N2MxAQcSE2NYRzSXCV79ReyrZKAZ3ddoSHeOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+QFKsubIF1XIMI5ZlwkuqXYmOTENsY38HLXn6DHwr8s=; b=rHo70hgF8H2rpnwRsewtyf9qeD/UNDneHK2q3GVUmcWXaluGsN056r3QCahh8/0NMt ulq+H9NYqq0fVHi6rkhQW3BcOhhhC0ExkWmb3C47I43vOy/mn75t50tUtB5Z4jP/Lf7C sgCzYViw9Ycf2eZnRTRKXw+QlRPCrjJyrnB44rL0ZJr6YjNm0SWPgwgkP/HJ9/AXlmul cAzVsuOBPFMLAYKQFPRsrVLNEOJhQNjZKahQvfUVy0VHE5c4crUQ8JtaM6o6OmsVRc/N CCO7m6UqK8Bi2NU46EH/eoOX2bua/Rgz5fOFeFXDHg4sxPonv4RsGZk3XW51nUJ84tZw WbTw== X-Gm-Message-State: APjAAAVu3BgZjYj/etmNbclFlVXoiKJNuliFzzUdu6haNKhVGXh75ArQ iLimU36EjVjX34E6gmO1QgvA7sV9eG4= X-Google-Smtp-Source: APXvYqwyC9TbiLV3ToI7EnvGeB085/6z9N0eGMjmlXRxVOvXzihg7vAaXQhroXfH2HKIbnYXib3V7A== X-Received: by 2002:a5d:984e:: with SMTP id p14mr12692044ios.115.1580140221979; Mon, 27 Jan 2020 07:50:21 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:21 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 17/21] bloblist: Zero records when adding Date: Mon, 27 Jan 2020 08:49:52 -0700 Message-Id: <20200127084920.17.I6864f6c3746a7a08437504d012456c9f14f3ee08@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean It is convenient for bloblist to zero out the contents of a records when it is added. This saves the callers having to do it. Update the API accordingly. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- common/bloblist.c | 3 +++ doc/README.bloblist | 4 ++-- test/bloblist.c | 27 +++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/common/bloblist.c b/common/bloblist.c index e2b7cc62e0..20a20ae0c0 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -73,6 +73,9 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) rec->hdr_size = sizeof(*rec); rec->size = size; rec->spare = 0; + + /* Zero the record data */ + memset(rec + 1, '\0', rec->size); *recp = rec; return 0; diff --git a/doc/README.bloblist b/doc/README.bloblist index b0e787b97d..274c460557 100644 --- a/doc/README.bloblist +++ b/doc/README.bloblist @@ -55,8 +55,8 @@ a single bloblist. API --- -Bloblist provides a fairly simple API which allows blobs to be created and -found. All access is via the blob's tag. +Bloblist provides a fairly simple API which allows blobs to be created and +found. All access is via the blob's tag. Blob records are zeroed when added. Finishing the bloblist diff --git a/test/bloblist.c b/test/bloblist.c index c78b58ea29..bdcca0291c 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -34,13 +34,31 @@ static struct bloblist_hdr *clear_bloblist(void) { struct bloblist_hdr *hdr; - /* Clear out any existing bloblist so we have a clean slate */ + /* + * Clear out any existing bloblist so we have a clean slate. Zero the + * header so that existing records are removed, but set everything else + * to 0xff for testing purposes. + */ hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE); - memset(hdr, '\0', TEST_BLOBLIST_SIZE); + memset(hdr, '\xff', TEST_BLOBLIST_SIZE); + memset(hdr, '\0', sizeof(*hdr)); return hdr; } +static int check_zero(void *data, int size) +{ + u8 *ptr; + int i; + + for (ptr = data, i = 0; i < size; i++, ptr++) { + if (*ptr) + return -EINVAL; + } + + return 0; +} + static int bloblist_test_init(struct unit_test_state *uts) { struct bloblist_hdr *hdr; @@ -84,10 +102,14 @@ static int bloblist_test_blob(struct unit_test_state *uts) data = bloblist_find(TEST_TAG, TEST_SIZE); ut_asserteq_ptr(rec + 1, data); + /* Check the data is zeroed */ + ut_assertok(check_zero(data, TEST_SIZE)); + /* Check the 'ensure' method */ ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2)); rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN)); + ut_assertok(check_zero(data, TEST_SIZE)); /* Check for a non-existent record */ ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); @@ -112,6 +134,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts) size = TEST_SIZE; ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); ut_asserteq(TEST_SIZE, size); + ut_assertok(check_zero(data, TEST_SIZE)); /* Check that we get the same thing again */ ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); From patchwork Mon Jan 27 15:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229919 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=DR/sYLKK; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vRt3kQ4z9sNx for ; Tue, 28 Jan 2020 02:53:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 683BE81A60; Mon, 27 Jan 2020 16:51:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="DR/sYLKK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67B0081A2E; Mon, 27 Jan 2020 16:50:36 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 1BBB481A1F for ; Mon, 27 Jan 2020 16:50:24 +0100 (CET) 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-io1-xd44.google.com with SMTP id h8so10510993iob.2 for ; Mon, 27 Jan 2020 07:50:23 -0800 (PST) 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=+hF4j94nt0wwPi5EJz0uv9nXTgHAGUpxGqHEBxi95vk=; b=DR/sYLKKvFmQ/g/17pK0uAHKopuzbzw9L5LezH3SHe0h4D9FeuAEuWaYifolY0vqJz coupje2mOsMLZeB2JL0AehvkB3bU6yvR+zhQkuf1ZNeHKdZcBecAH6rE0CnlsaeSlM2O zN7mJ/qF8uP2G9WsqVM014G/BvQ9dp4SKwAJk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+hF4j94nt0wwPi5EJz0uv9nXTgHAGUpxGqHEBxi95vk=; b=h6jYwTpmZlInXWYO9eJ5Ot5ahNGZ3l27g7t1PFo+M9gQ1aU6MdX/XAMqFfMXOFyQHS oMD9vPQiBHvevOILsirW87r3266/Z6Kxzi71r7qFSYhSva2hQcb/kPGramCUSdMtTq14 lreGT0CTXR26K+yod1LY6XABAcCxPLFBVTYICiigz2TrI73hnDDjaKkDHAnKp4TDkAKL ciWdiCPjGdBH5TWmzglWxC8wsDa03DctUQSZpecNMEGNUuaYsKcWgNOxbK+rBVFOCLJK KngZWLuYJ7V7JQ56m6Da7E2f7eFgtVOfwEXTll/5mnUHIgJx5Y9YplAZLOYpJhnn8EHA u0eA== X-Gm-Message-State: APjAAAVxGqqd2Maz6nlxHAgLM52ZQcKLYPUN9QI4n+C0ny/cNk0p3pcG GvkLwUZxAYBUqGuXgwhEWyF26AqDvGE= X-Google-Smtp-Source: APXvYqx424cvs58HlFIYxccjUa29OTNCtpo5+LKo313y5AGo9o7SBaBc1j0stPzEwPTtJf47HpTX2g== X-Received: by 2002:a05:6638:a2c:: with SMTP id 12mr13902097jao.60.1580140222651; Mon, 27 Jan 2020 07:50:22 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:22 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 18/21] sandbox: pmic: Correct i2c pmic emulator platdata method Date: Mon, 27 Jan 2020 08:49:53 -0700 Message-Id: <20200127084920.18.I296e8199523e08dced6bb64d6984b84753ec64c6@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean This currently reads the uclass's private data in the ofdata_to_platdata method which is not allowed, since the uclass has not read it from the device tree. This happens in the probe method. Fix it by adding a probe() method and moving the code there. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/power/pmic/i2c_pmic_emul.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/power/pmic/i2c_pmic_emul.c b/drivers/power/pmic/i2c_pmic_emul.c index 80efc0265d..b58c8302cf 100644 --- a/drivers/power/pmic/i2c_pmic_emul.c +++ b/drivers/power/pmic/i2c_pmic_emul.c @@ -105,12 +105,21 @@ static int sandbox_i2c_pmic_ofdata_to_platdata(struct udevice *emul) { struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul); struct udevice *pmic_dev = i2c_emul_get_device(emul); - struct uc_pmic_priv *priv = dev_get_uclass_priv(pmic_dev); - const u8 *reg_defaults; debug("%s:%d Setting PMIC default registers\n", __func__, __LINE__); plat->reg_count = pmic_reg_count(pmic_dev); - plat->trans_len = priv->trans_len; + + return 0; +} + +static int sandbox_i2c_pmic_probe(struct udevice *emul) +{ + struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul); + struct udevice *pmic_dev = i2c_emul_get_device(emul); + struct uc_pmic_priv *upriv = dev_get_uclass_priv(pmic_dev); + const u8 *reg_defaults; + + plat->trans_len = upriv->trans_len; plat->buf_size = plat->reg_count * plat->trans_len; plat->reg = calloc(1, plat->buf_size); @@ -149,6 +158,7 @@ U_BOOT_DRIVER(sandbox_i2c_pmic_emul) = { .id = UCLASS_I2C_EMUL, .of_match = sandbox_i2c_pmic_ids, .ofdata_to_platdata = sandbox_i2c_pmic_ofdata_to_platdata, + .probe = sandbox_i2c_pmic_probe, .platdata_auto_alloc_size = sizeof(struct sandbox_i2c_pmic_plat_data), .ops = &sandbox_i2c_pmic_emul_ops, }; From patchwork Mon Jan 27 15:49:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229921 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=TkDvq2Fd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vSG71vzz9sPJ for ; Tue, 28 Jan 2020 02:54:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EFF8781A5E; Mon, 27 Jan 2020 16:51:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="TkDvq2Fd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B56781A2A; Mon, 27 Jan 2020 16:50:37 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 8E25B81A29 for ; Mon, 27 Jan 2020 16:50:24 +0100 (CET) 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-io1-xd42.google.com with SMTP id z193so10522643iof.1 for ; Mon, 27 Jan 2020 07:50:24 -0800 (PST) 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=hbR1jr6sZ4yxPqij3PVUGqdkc9NC7HftQvo2Ts8wLqs=; b=TkDvq2FdxXOrh/3xKTe/y+JZ2Ye7gUaT514KZfsx6cT/Vvw6YyBDACUXoEsQ09fJzc kSSA1Txy95hB0fgNMvAu1Jxy0Y6/vn+T3DUFCfzDbzSOtjeWZxJu9/lp6KLbXJXYYfDF hIRZ0pjoH7n0IfXMYTlqca7KmJSp5lNw9NVpQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hbR1jr6sZ4yxPqij3PVUGqdkc9NC7HftQvo2Ts8wLqs=; b=QqfgTB50XdYpkURC3GRS1hYoDeQ9DDOBeoQzgBl74iko9F+RQXp2P21s0zqeSzORGg GiH8+8uW1/YfjNCAMdCj7pXZh5WV3WiIxeNN1/v8e9nR3zLaLLzn6C9Rcw9QRzDyv3Nq tb+nYVR7i62zAUBKXv2Y4cbTd3G3dIToHx9AfzX2qBuotF/vVQiXfa/Qr91ilr73FAN9 zAQ2/H8GDPgtG1SpHOh7nc8VF8YIycJ/P+pz2BywWc9mBZXvxp8wVym0L8YFB12v/8Ww 8ogUGfLRbeIxwFThBhP3mJLZCVMJoQiGKWvyW1i1RLbC+00rR0gOakBNk4sa8zGEKY18 fo1Q== X-Gm-Message-State: APjAAAVMbyInPUtVhXitYWx1LSXv8J0pipA4hOCQNP4Iv5FZEBcYGcTU xkr3gIDcsddClp04s8KDzYSziOwTwXE= X-Google-Smtp-Source: APXvYqz/ZjPnIpx7iVTyRpa/n9WtjpjDNCbvvaVzH0KbOIsqVSVNSB/GFbwoMiSMo8DejctgcJstjw== X-Received: by 2002:a6b:3845:: with SMTP id f66mr13681494ioa.102.1580140223287; Mon, 27 Jan 2020 07:50:23 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:23 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 19/21] console: Add a function to read a line of the output / eof Date: Mon, 27 Jan 2020 08:49:54 -0700 Message-Id: <20200127084920.19.I8114ed3d67267c833b7d9f456e6da6e9c4653c9b@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joe Hershberger Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean When recording the console output for testing it is useful to be able to read the output a line at a time to check that the output is correct. Also we need to check that we get to the end of the output. Add a console function to return the next line and another to see how must data is left. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- common/console.c | 11 +++++++++++ include/console.h | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/common/console.c b/common/console.c index 168ba60d0d..7681da19a2 100644 --- a/common/console.c +++ b/common/console.c @@ -621,6 +621,17 @@ void console_record_reset_enable(void) console_record_reset(); gd->flags |= GD_FLG_RECORD; } + +int console_record_readline(char *str, int maxlen) +{ + return membuff_readline(&gd->console_out, str, maxlen, ' '); +} + +int console_record_avail(void) +{ + return membuff_avail(&gd->console_out); +} + #endif /* test if ctrl-c was pressed */ diff --git a/include/console.h b/include/console.h index e935c601f1..74afe22b7e 100644 --- a/include/console.h +++ b/include/console.h @@ -41,6 +41,25 @@ void console_record_reset(void); */ void console_record_reset_enable(void); +/** + * console_record_readline() - Read a line from the console output + * + * This reads the next available line from the console output previously + * recorded. + * + * @str: Place to put string + * @maxlen: Maximum length of @str including nul terminator + * @return length of string returned + */ +int console_record_readline(char *str, int maxlen); + +/** + * console_record_avail() - Get the number of available bytes in console output + * + * @return available bytes (0 if empty) + */ +int console_record_avail(void); + /** * console_announce_r() - print a U-Boot console on non-serial consoles * From patchwork Mon Jan 27 15:49:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229920 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=TAP1jGon; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vS43wwRz9sPJ for ; Tue, 28 Jan 2020 02:53:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4D1ED81A68; Mon, 27 Jan 2020 16:51:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="TAP1jGon"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D65FB81A21; Mon, 27 Jan 2020 16:50:37 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 53D2C819A9 for ; Mon, 27 Jan 2020 16:50:25 +0100 (CET) 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-io1-xd44.google.com with SMTP id z193so10522687iof.1 for ; Mon, 27 Jan 2020 07:50:25 -0800 (PST) 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=VfzuRdVZ25ZywkPknIxkvbeNJRLH7IOhtb+pLtUInKg=; b=TAP1jGonJvP/zqYHIdb2y11Nm0WiqC5v/YHYIM/X5nO3fj5iS6R0igbYqqQfH/8vac mMZ1Jifj2Fy/E5Wq9F1Vv+LqSGodyjQQPVtH+M5ayHTdWFseDNkGjquEIRiC0jHEV2mP 5PYes1JQjhaqnWt4JeRgvOOJKP271VMxjklm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VfzuRdVZ25ZywkPknIxkvbeNJRLH7IOhtb+pLtUInKg=; b=g5JiyH0CJ4/+BzvtandsKKJMLrwOMUXke3nNxRgGHKktlgBO6dTaMe2Y9bMStWfVm2 gS3K6Tq63HpOXfVZvtR1do3icDuuD9qkK4vO03/+U7DUpH4LI01CL4a5KWRjk/SHZhdx 2Qbzhv7IyjC3jjmwv0g03pNWmPfXb/QNWn+Mgco/KtB8D/sVjNaKGeB0XuGAqefv5wHz +u9BY+jVwsntk1U7Wk7cqLhStFE5pN2YncMrMnIdCPNzaqgzcgCG3+URK82KzPTFGtxR mElkLNPGRtTvb4XMfyTdvhzNbIp+9ET0+ijyQNEcRn5qJeXNZdtuxRmteOinnJS3oTrH sK+A== X-Gm-Message-State: APjAAAXfz/5AUE0RoZP9/dF8dfUj5ElZD0A+jkDgKMYeW0QIoDNhSv1W PO0QC2t7Z6VtCmkuX9uvfKZkDl/3Jts= X-Google-Smtp-Source: APXvYqyKE/ItmTm+1rGKtQvLMOm/dx4ZHDmFWWjTf4osxATkRDUUdkeRPyqiq8q4eaW1ksM+wcCNsw== X-Received: by 2002:a02:ce87:: with SMTP id y7mr10834827jaq.26.1580140223982; Mon, 27 Jan 2020 07:50:23 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:23 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 20/21] test: Enable console recording in tests Date: Mon, 27 Jan 2020 08:49:55 -0700 Message-Id: <20200127084920.20.I0d843e524c54d3c7a29919c95929b1909b9eaa61@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean At present we reset the console buffer before each test but do not actually set the recording flag. Without this, the output is not recorded. Update the code to set the flag before the test and clear it afterwards. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- test/dm/test-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 72648162a9..d7dc8d1f91 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -97,11 +97,11 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, * Silence the console and rely on console recording to get * our output. */ - console_record_reset(); + console_record_reset_enable(); if (!state->show_test_output) gd->flags |= GD_FLG_SILENT; test->func(uts); - gd->flags &= ~GD_FLG_SILENT; + gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); state_set_skip_delays(false); ut_assertok(dm_test_destroy(uts)); From patchwork Mon Jan 27 15:49:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229922 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=UX+siB/4; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 485vST64hsz9sPJ for ; Tue, 28 Jan 2020 02:54:17 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 08B5481A69; Mon, 27 Jan 2020 16:51:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="UX+siB/4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 239F581A2E; Mon, 27 Jan 2020 16:50:41 +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=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 22F1981A17 for ; Mon, 27 Jan 2020 16:50:26 +0100 (CET) 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-io1-xd41.google.com with SMTP id n11so10499614iom.9 for ; Mon, 27 Jan 2020 07:50:25 -0800 (PST) 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=VzFfyLRxeWiTZzX66BVNU2KahTbbXNcT2oVmjMrgwBc=; b=UX+siB/4JXV2zeOeqZPD8BkDY+5pF9+rRstNuH8FO5/cgDWOZsfyUhusURyj05e5Ag REZHwtubHgftXSHoYjXaqv41pDogSo+Tfrm+tHEVACdKDkvgcIpkxihh7dP0ckpyELPL ruAeRh5f3rxBuR7opScQvxLS6oM1XqqMz4vsQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VzFfyLRxeWiTZzX66BVNU2KahTbbXNcT2oVmjMrgwBc=; b=mhoSq4iyNK/anVyPTuKI+1y6U2vv9o8X5QCvgONQTXsexaohIffCtjXSX2dhCW4s5f t3SdMONjY+PC+rCbst+EoUn78A8ApqLLVWxtzvqqmPMZhbEGj1mGRtw1je7N3+eZXhp+ 3r9rvMM+Aaogt8KFaCwq1omdXyahNKgecCW+5IeL6hvWpeZBcUeMKP5/WmUKdiM4f/Jh gqt2McUhstWpAs+o2xbT0ZXA20XxFPIdg0gVExOhfepcW2c5wEbLaLO/CArsf/42+TKs maAqzrWHJ8lbxay05wC5Go/EuK8c9ey9czVjlMJEaOTFtdYxevz/JUEBAaONZFTDx7Zx ZzXA== X-Gm-Message-State: APjAAAWZnV0HAxTBGeKA9F0LT0RRhyQm+ImGTyvmAavf7TpCQwtaBLjS E3QFBOFm80wuXPnE6j2DyoWkYAas5iY= X-Google-Smtp-Source: APXvYqyqXmdoXWtyJ0uLwMoDVMxC5qnuQR5qqkH8uwcDloDMm3mAvn4/Gd7FSJr2gbyoGGoOJzBc6Q== X-Received: by 2002:a5d:84d1:: with SMTP id z17mr13039621ior.169.1580140224687; Mon, 27 Jan 2020 07:50:24 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v7sm3576560iom.58.2020.01.27.07.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:50:24 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 21/21] test: Add a way to check each line of console output Date: Mon, 27 Jan 2020 08:49:56 -0700 Message-Id: <20200127084920.21.I6e63c1c6aae518ed5a245427b8046b1bac3dbf66@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127154956.64368-1-sjg@chromium.org> References: <20200127154956.64368-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean When writing tests to check the output from commands it is useful to be able to check the output line by line using an assertion. Add helper macros to support this and to check that there is no unexpected trailing data. Also some commands produce a dump using print_buffer(). Add a way to check that the correct number of bytes are dumped (ignoring the actual contents). Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- include/test/test.h | 4 +++ include/test/ut.h | 65 +++++++++++++++++++++++++++++++++++++++++++++ test/ut.c | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/include/test/test.h b/include/test/test.h index e5bef4759a..2a75211008 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -15,12 +15,16 @@ * @start: Store the starting mallinfo when doing leak test * @priv: A pointer to some other info some suites want to track * @of_root: Record of the livetree root node (used for setting up tests) + * @expect_str: Temporary string used to hold expected string value + * @actual_str: Temporary string used to hold actual string value */ struct unit_test_state { int fail_count; struct mallinfo start; void *priv; struct device_node *of_root; + char expect_str[256]; + char actual_str[256]; }; /** diff --git a/include/test/ut.h b/include/test/ut.h index c9fc9cc839..04df8ba3af 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -38,6 +38,43 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, const char *func, const char *cond, const char *fmt, ...) __attribute__ ((format (__printf__, 6, 7))); +/** + * ut_check_console_line() - Check the next console line against expectations + * + * This creates a string and then checks it against the next line of console + * output obtained with console_record_readline(). + * + * After the function returns, uts->expect_str holds the expected string and + * uts->actual_str holds the actual string read from the console. + * + * @uts: Test state + * @fmt: printf() format string for the error, followed by args + * @return 0 if OK, other value on error + */ +int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) + __attribute__ ((format (__printf__, 2, 3))); + +/** + * ut_check_console_end() - Check there is no more console output + * + * After the function returns, uts->actual_str holds the actual string read + * from the console + * + * @uts: Test state + * @return 0 if OK (console has no output), other value on error + */ +int ut_check_console_end(struct unit_test_state *uts); + +/** + * ut_check_console_dump() - Check that next lines have a print_buffer() dump + * + * This only supports a byte dump. + * + * @total_bytes: Size of the expected dump in bytes` + * @return 0 if OK (looks like a dump and the length matches), other value on + * error + */ +int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); /* Assert that a condition is non-zero */ #define ut_assert(cond) \ @@ -149,6 +186,34 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, /* Assert that an operation succeeds (returns 0) */ #define ut_assertok(cond) ut_asserteq(0, cond) +/* Assert that the next console output line matches */ +#define ut_assert_nextline(fmt, args...) \ + if (ut_check_console_line(uts, fmt, ##args)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "\nExpected '%s',\n got '%s'", \ + uts->expect_str, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + +/* Assert that there is no more console output */ +#define ut_assert_console_end() \ + if (ut_check_console_end(uts)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "Expected no more output, got '%s'",\ + uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + +/* Assert that the next lines are print_buffer() dump at an address */ +#define ut_assert_nextlines_are_dump(total_bytes) \ + if (ut_check_console_dump(uts, total_bytes)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", \ + "Expected dump of length %x bytes, got '%s'", \ + total_bytes, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + /** * ut_check_free() - Return the number of bytes free in the malloc() pool * diff --git a/test/ut.c b/test/ut.c index 265da4a0d8..c64f0b554d 100644 --- a/test/ut.c +++ b/test/ut.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -46,3 +47,48 @@ long ut_check_delta(ulong last) return ut_check_free() - last; } +int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + va_end(args); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + + return strcmp(uts->expect_str, uts->actual_str); +} + +int ut_check_console_end(struct unit_test_state *uts) +{ + if (!console_record_avail()) + return 0; + + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + + return 1; +} + +int ut_check_console_dump(struct unit_test_state *uts, int total_bytes) +{ + char *str = uts->actual_str; + int upto; + + /* Handle empty dump */ + if (!total_bytes) + return 0; + + for (upto = 0; upto < total_bytes;) { + int len; + int bytes; + + len = console_record_readline(str, sizeof(uts->actual_str)); + if (str[8] != ':' || str[9] != ' ') + return 1; + + bytes = len - 8 - 2 - 3 * 16 - 4; + upto += bytes; + } + + return upto == total_bytes ? 0 : 1; +}