From patchwork Mon Jan 27 05:05: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: 1229537 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=lA5Qo9gX; 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 485dHm1227z9sR1 for ; Mon, 27 Jan 2020 16:15:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5620681856; Mon, 27 Jan 2020 06:11: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="lA5Qo9gX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F58181835; Mon, 27 Jan 2020 06:09: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-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 19251817DD for ; Mon, 27 Jan 2020 06:08:58 +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 x1so8555260iop.7 for ; Sun, 26 Jan 2020 21:08:58 -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=unaDXL5HftX46LGLuxkGq1KmQJ3whfdR3l8OJG7IIz8=; b=lA5Qo9gX0KBKOEdc4iskmUt76Fma5jHIWPeltLlMoid73QdA0ahDin/JkCMrt3Ejjn thlbeQA6vNizOiDRXGVNQ7lY0VdBJ4X/grjpxmwPgPcOeBk91xJ6yvFpjjGaaFZ6I+EL DluFylDeIzd+W1ZegSxHsk3hOOin2+uE1JhKg= 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=unaDXL5HftX46LGLuxkGq1KmQJ3whfdR3l8OJG7IIz8=; b=W8zJBN5NdiHDcn7BOo3/RH6Cn0Xx5n8YQ/89Qj/lvwupx1EDxgO6XuZmjqOdj3LH81 PaR3ttQvdDe6EynpLQSjMSqZJeXHscqpeyt++esT6idYggBQns6XDr6QFB+kM6gA1ZK3 +084I9i9w5BfZZQSn8uXp9V9+PAKWISGemLH71tbPVz/s9s7+HwtIfL7ow876OIQJbyv MVnH35O3LpUhV1+xj4oLA+gYWDvrVFi/HW6Bh6PlHSl068Ms4CG4/Mv2hNSl1Q51L1BN tvNidlTBlMCJ6NwRh/I6kJom0YqETAMz++SGLCcU9X/na/RYTORAlgofr7zpmZZ3T6oD Du3w== X-Gm-Message-State: APjAAAWvdlvczymIpTvyEzl/lSHDe3EVLpR/u6NJGdoRQ1AfRIydPAYI P1FQq6K6jv/qx6EnPI5qt4zBf9/vcTyKYg== X-Google-Smtp-Source: APXvYqwxrNneOaPdqaCXHBHKhwUFgHoHrnFgSjv89iXMYwytZPjln62K3QbANDQhripsOHdbfRX3rA== X-Received: by 2002:a5e:8e4c:: with SMTP id r12mr10889934ioo.119.1580101736702; Sun, 26 Jan 2020 21:08:56 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h23sm4313195ilf.57.2020.01.26.21.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 21:08:56 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 041/108] dm: acpi: Enhance acpi_get_name() Date: Sun, 26 Jan 2020 22:05:48 -0700 Message-Id: <20200126220508.41.I1a77e678d7c6973796cc651ac6d858e1122bb7ae@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127050655.170614-1-sjg@chromium.org> References: <20200127050655.170614-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 For many device types it is possible to figure out the name just by looking at its uclass or parent. Add a function to handle this, since it allows us to cover the vast majority of cases automatically. However it is sometimes impossible to figure out an ACPI name for a device just by looking at its uclass. For example a touch device may have a vendor-specific name. Add a new "acpi,name" property to allow a custom name to be created. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 1 + doc/device-tree-bindings/device.txt | 13 +++++++++ drivers/core/acpi.c | 11 +++++++- include/dm/device.h | 2 +- test/dm/acpi.c | 42 ++++++++++++++++++++++++++++- 5 files changed, 66 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index f60f0adc05..410235fae3 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -94,6 +94,7 @@ int-value = <1234>; uint-value = <(-1234)>; interrupts-extended = <&irq 3 0>; + acpi,name = "GHIJ"; }; junk { diff --git a/doc/device-tree-bindings/device.txt b/doc/device-tree-bindings/device.txt index e625e67f43..61ebd7a942 100644 --- a/doc/device-tree-bindings/device.txt +++ b/doc/device-tree-bindings/device.txt @@ -18,6 +18,8 @@ U-Boot provides for some optional properties which are documented here. - acpi,hid-desc-reg-offset : HID register offset (for Human Interface Devices) - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that Linux will not re-init the device + - acpi,name : Provides the ACPI name for a device, which is a string consisting + of four alphanumeric character (upper case) - acpi,uid : _UID value for device @@ -35,3 +37,14 @@ synaptics_touchpad: synaptics-touchpad@2c { acpi,probed; acpi,hid-desc-reg-offset = <0x20>; }; + +pcie-a0@14,0 { + reg = <0x0000a000 0 0 0 0>; + acpi,name = "RP01"; + wifi: wifi { + compatible = "intel,generic-wifi"; + acpi,desc = "Intel WiFi"; + acpi,name = "WF00"; + interrupts-extended = <&acpi_gpe 0x3c 0>; + }; +}; diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 657753ebb3..ba02b04636 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -9,6 +9,7 @@ #define LOG_CATEOGRY LOGC_ACPI #include +#include #include #include #include @@ -51,12 +52,20 @@ int acpi_return_name(char *out_name, const char *name) int acpi_get_name(const struct udevice *dev, char *out_name) { struct acpi_ops *aops; + const char *name; + int ret; aops = device_get_acpi_ops(dev); if (aops && aops->get_name) return aops->get_name(dev, out_name); + name = dev_read_string(dev, "acpi,name"); + if (name) + return acpi_return_name(out_name, name); + ret = acpi_device_get_name(dev, out_name); + if (ret) + return log_msg_ret("dev", ret); - return -ENOSYS; + return 0; } /** diff --git a/include/dm/device.h b/include/dm/device.h index c2e12cd151..03d7ef1bb3 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -713,7 +713,7 @@ int dev_enable_by_path(const char *path); */ static inline bool device_is_on_pci_bus(const struct udevice *dev) { - return device_get_uclass_id(dev->parent) == UCLASS_PCI; + return dev->parent && device_get_uclass_id(dev->parent) == UCLASS_PCI; } /** diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 16dc0955be..c87bd8569d 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -93,12 +93,52 @@ UCLASS_DRIVER(testacpi) = { static int dm_test_acpi_get_name(struct unit_test_state *uts) { char name[ACPI_NAME_MAX]; - struct udevice *dev; + struct udevice *dev, *dev2, *i2c, *spi, *serial, *timer, *sound; + struct udevice *pci, *root; + /* Test getting the name from the driver */ ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev)); ut_assertok(acpi_get_name(dev, name)); ut_asserteq_str(ACPI_TEST_DEV_NAME, name); + /* Test getting the name from the device tree */ + ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test", + &dev2)); + ut_assertok(acpi_get_name(dev2, name)); + ut_asserteq_str("GHIJ", name); + + /* Test getting the name from acpi_device_get_name() */ + ut_assertok(uclass_first_device(UCLASS_I2C, &i2c)); + ut_assertok(acpi_get_name(i2c, name)); + ut_asserteq_str("I2C0", name); + + ut_assertok(uclass_first_device(UCLASS_SPI, &spi)); + ut_assertok(acpi_get_name(spi, name)); + ut_asserteq_str("SPI0", name); + + /* The uart has no sequence number, so this should fail */ + ut_assertok(uclass_first_device(UCLASS_SERIAL, &serial)); + ut_asserteq(-ENXIO, acpi_get_name(serial, name)); + + /* ACPI doesn't know about the timer */ + ut_assertok(uclass_first_device(UCLASS_TIMER, &timer)); + ut_asserteq(-ENOENT, acpi_get_name(timer, name)); + + /* May as well test the rest of the cases */ + ut_assertok(uclass_first_device(UCLASS_SOUND, &sound)); + ut_assertok(acpi_get_name(sound, name)); + ut_asserteq_str("HDAS", name); + + ut_assertok(uclass_first_device(UCLASS_PCI, &pci)); + ut_assertok(acpi_get_name(pci, name)); + ut_asserteq_str("PCI0", name); + + ut_assertok(uclass_first_device(UCLASS_ROOT, &root)); + ut_assertok(acpi_get_name(root, name)); + ut_asserteq_str("\\_SB", name); + + /* Note that we don't have tests for acpi_name_from_id() */ + return 0; } DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);