From patchwork Mon Jan 27 05:05: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: 1229532 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=QFpZS84H; 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 485dGn5shnz9sR1 for ; Mon, 27 Jan 2020 16:14:57 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 18E4681841; Mon, 27 Jan 2020 06:11:17 +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="QFpZS84H"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5ED108182B; Mon, 27 Jan 2020 06:09:22 +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 1F776817D4 for ; Mon, 27 Jan 2020 06:08:54 +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 k24so8558926ioc.4 for ; Sun, 26 Jan 2020 21:08:54 -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=QEcJSlddCdYZQM574lfpCV67vS3+SjFOU8whZXh7GcA=; b=QFpZS84HUI01yohYCcceeh5VxH3cOLWRve9OKr1sBa/+K6XgahulQK3/GjHFexkrFv IFhxufEF7O1DwvsLxR0Qw5jDddJPD6klr0SvG2XjzeNi2MedeKlr2WAYu6IB91gfcTso Y72/cAcMwRCUkOr7uZUCMoPYxE9Xo84Yl8Ork= 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=QEcJSlddCdYZQM574lfpCV67vS3+SjFOU8whZXh7GcA=; b=BzNjokrr763QrP0DUIjuDCm8RAWu3LfSxPJln+ypr/ME3YluwgQciXgRAZRQzARGgZ CyQmpA54yzxm0cue7NFPZsHbK7Ihg/mBlO3bh5FnMIV9G1MOxyhlwVA5wEUa0vboCf27 2+PaY5Q5w/7BompH4wkJEYauU7zlYNw4psCD2OQJFkD9QPWVbUlDFqywGyBxudCLcZJt cpVO4gHK6TJNVyBLUWDSB1d80hOdO17zOXnIyPJf9nEl5UTCfCk3/j4uEBADJ5ekg+dZ 3mtd6XNxrl3u5th3DA9JXz9TYGl5oOn/ZC3cv4b64nQy9n/VjzQ5Fr7UlCZ8YnJuEzzK 9Kgg== X-Gm-Message-State: APjAAAXFi+pu5GNSHvFUn2hUQESTS4pCz/YzTH+rrHzCFTZkqm6+6vku B/jxb1T0kVVHNqWhZ78eWpGMqnpFHhqU1w== X-Google-Smtp-Source: APXvYqwd6KxGacI/aq5zNqVfaQvETZQydzjE0lm5Y0XdMTVvXNYiR/Leyebjvh0h2d7QU+wYqpVdBQ== X-Received: by 2002:a6b:8e47:: with SMTP id q68mr10821780iod.274.1580101732838; Sun, 26 Jan 2020 21:08:52 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 21:08:52 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 036/108] acpi: Support ordering SSDT data by device Date: Sun, 26 Jan 2020 22:05:43 -0700 Message-Id: <20200126220508.36.I91d8e58921d27a54f6ecb58ecd5b72d141238f63@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: , 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 /chosen property to control the order in which the data appears in the SSDT. This allows matching up U-Boot's output from a dump of the known-good data obtained from within Linux. Signed-off-by: Simon Glass --- arch/sandbox/dts/test.dts | 5 ++- doc/device-tree-bindings/chosen.txt | 9 +++++ drivers/core/acpi.c | 61 +++++++++++++++++++++++++++++ test/dm/acpi.c | 17 ++++---- 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 3351f92165..100953452a 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -206,12 +206,12 @@ compatible = "denx,u-boot-devres-test"; }; - acpi-test { + acpi_test1: acpi-test { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "ab"; }; - acpi-test2 { + acpi_test2: acpi-test2 { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "cd"; }; @@ -822,6 +822,7 @@ chosen { #address-cells = <1>; #size-cells = <1>; + u-boot,acpi-ssdt-order = <&acpi_test2 &acpi_test1>; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>; diff --git a/doc/device-tree-bindings/chosen.txt b/doc/device-tree-bindings/chosen.txt index 395c9501e3..d4dfc05847 100644 --- a/doc/device-tree-bindings/chosen.txt +++ b/doc/device-tree-bindings/chosen.txt @@ -134,3 +134,12 @@ Example phandlepart = <&mmc 1>; }; }; + +u-boot,acpi-ssdt-order +---------------------- + +This provides the ordering to use when writing device data to the ACPI SSDT +(Secondary System Descriptor Table). Each cell is a phandle pointer to a device +node to add. The ACPI information is written in this order. + +If the ordering does not include all nodes, an error is generated. diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index d7ab906757..b8e192dce5 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -95,6 +95,63 @@ static int acpi_add_item(struct acpi_ctx *ctx, struct udevice *dev, return 0; } +struct acpi_item *find_item(const char *devname) +{ + int i; + + for (i = 0; i < item_count; i++) { + struct acpi_item *item = &acpi_item[i]; + + if (!strcmp(devname, item->dev->name)) + return item; + } + + return NULL; +} + +static int build_type(struct acpi_ctx *ctx, void *start, enum gen_type_t type) +{ + const u32 *order; + int size; + int count; + void *ptr; + void *end = ctx->current; + + ptr = start; + order = ofnode_get_chosen_prop("u-boot,acpi-ssdt-order", &size); + if (!order) { + log_warning("Failed to find ordering, leaving as is\n"); + return 0; + } + + count = size / sizeof(u32); + while (count--) { + struct acpi_item *item; + const char *name; + ofnode node; + + node = ofnode_get_by_phandle(fdt32_to_cpu(*order++)); + name = ofnode_get_name(node); + item = find_item(name); + if (!item) { + log_err("Failed to find item '%s'\n", name); + return log_msg_ret("find", -ENOENT); + } + if (item->type == type) { + log_debug(" - add %s\n", item->dev->name); + memcpy(ptr, item->buf, item->size); + ptr += item->size; + } + } + + if (ptr != end) { + log_warning("*** Missing bytes: ptr=%p, end=%p\n", ptr, end); + return -ENXIO; + } + + return 0; +} + int _acpi_fill_ssdt(struct acpi_ctx *ctx, struct udevice *parent) { struct acpi_ops *aops; @@ -130,11 +187,15 @@ int _acpi_fill_ssdt(struct acpi_ctx *ctx, struct udevice *parent) int acpi_fill_ssdt(struct acpi_ctx *ctx) { + void *start = ctx->current; int ret; log_debug("Writing SSDT tables\n"); ret = _acpi_fill_ssdt(ctx, dm_root()); log_debug("Writing SSDT finished, err=%d\n", ret); + ret = build_type(ctx, start, TYPE_SSDT); + if (ret) + return log_msg_ret("build", ret); return ret; } diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 50d6ec91f7..3221563ca6 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -336,16 +336,19 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) ut_assertnonnull(buf); ctx.current = buf; - buf[4] = 'z'; /* sentinal */ + buf[4] = 'z'; /* sentinel */ ut_assertok(acpi_fill_ssdt(&ctx)); - /* These values come from acpi-test's acpi-ssdt-test-data property */ - ut_asserteq('a', buf[0]); - ut_asserteq('b', buf[1]); + /* + * These values come from acpi-test2's acpi-ssdt-test-data property. + * This device comes first because of u-boot,acpi-ssdt-order + */ + ut_asserteq('c', buf[0]); + ut_asserteq('d', buf[1]); - /* These values come from acpi-test2's acpi-ssdt-test-data property */ - ut_asserteq('c', buf[2]); - ut_asserteq('d', buf[3]); + /* These values come from acpi-test's acpi-ssdt-test-data property */ + ut_asserteq('a', buf[2]); + ut_asserteq('b', buf[3]); ut_asserteq('z', buf[4]);