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);