From patchwork Sun Apr 26 15:19: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: 1277081 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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=OrgqRQ0g; 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 499BS55g0qz9sRY for ; Mon, 27 Apr 2020 01:20:37 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 55E6C81D36; Sun, 26 Apr 2020 17:20:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="OrgqRQ0g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5EA2F81D25; Sun, 26 Apr 2020 17:20:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 4D79581D00 for ; Sun, 26 Apr 2020 17:19:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x142.google.com with SMTP id i16so14296001ils.12 for ; Sun, 26 Apr 2020 08:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QWr4rz6ZlpelM6rNgKZZnSZQWUhfGKF+Kr9TQPKIFpg=; b=OrgqRQ0gPztBFjrXZUqXnjrgKmPD5GlzWOy/h0OcOixRSpHZEh4ovlsVmacz6bQ4GI TmbfS2vNumA7VgVeuGybOJOUi+bWdwsXV49dYzls5tKH6GqAIequHZ8layUgtcO7rL8Q 4o+lbI6+kM1J4u1JSi9Q1VkkmPxeIWw6icUic= 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=QWr4rz6ZlpelM6rNgKZZnSZQWUhfGKF+Kr9TQPKIFpg=; b=V/PkwzMRLY5R/sixL7o2/XRYEhfGlq1TtFYhh4dpLFvlqU7vkuSXMAZvfSr06dh4Gl vXWTCcKy43PXhf+/yMD+hWlwiqP4qswnGNuCqX3yemF1dqOJkFvwc/UCXekmzv24/1gx PI8j1miQ9U0SM8XkPE0wgU4GTX2IXVzzMY83ZJR8bn9u+sryW3hGOkWeYdLAzLbc42kQ O0VWwcdTVieQWNcOkEUU239VhdrEKBMi2X/3GEWlMXlmgJmhgov5qN0yAzQhJttorT0k QrHYPPazLPUoUsnuhjAviboWag9Ld8tC7mbGb8bQWu5+bhQ+5M2HO/8OtgpQupQzndj6 Kg0Q== X-Gm-Message-State: AGi0Pub4MomWBwAtlV5YbbcHcy7wMSkojtIge9Gy8C/U/lvZkbLPsUwS +E6JDwFge1sEz5+zgj13Nq51bbWPducuwA== X-Google-Smtp-Source: APiQypL5HKWIWYzqlOK5S6FIwGVTApPL+NSPKViOZZLktQL4wP+C1HjYYyiDQXg+KUh1by4YWBwouA== X-Received: by 2002:a92:c6c4:: with SMTP id v4mr15985272ilm.18.1587914397892; Sun, 26 Apr 2020 08:19:57 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:19:57 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 1/9] acpi: Add a binding for ACPI settings in the device tree Date: Sun, 26 Apr 2020 09:19:45 -0600 Message-Id: <20200426091948.v8.1.I7842b2dd0d6b475301fc044c6640d8089873053f@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Devices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree. Add a binding file to describe this. Signed-off-by: Simon Glass --- Changes in v8: None Changes in v7: None Changes in v5: None Changes in v4: - Put 'interrupts-extended' property on one line - Rename acpi-probed to linux,probed - Note that linux,probed is an out-of-tree feature Changes in v3: - Drop mention of PRIC - Rename acpi,desc to acpi,ddn - Correct description of acpi,probed - Drop hid-descr-addr - Just add the device.txt binding file in this patch - Change the example to ELAN - Add a pointer to information about acpi,compatible Changes in v2: - Fix definition of HID - Infer hid-over-i2c CID value - Add the hid-over-i2c binding document doc/device-tree-bindings/device.txt | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 doc/device-tree-bindings/device.txt diff --git a/doc/device-tree-bindings/device.txt b/doc/device-tree-bindings/device.txt new file mode 100644 index 0000000000..27bd3978d9 --- /dev/null +++ b/doc/device-tree-bindings/device.txt @@ -0,0 +1,36 @@ +Devices +======= + +Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented here. See +also hid-over-i2c.txt which describes HID devices. See also +Documentation/firmware-guide/acpi/enumeration.rst in the Linux kernel for +the acpi,compatible property. + + - acpi,has-power-resource : (boolean) true if this device has a power resource. + This causes an ACPI PowerResource to be written containing the properties + provided by this binding, to describe how to handle powering the device up + and down using GPIOs + - acpi,compatible : compatible string to report + - acpi,ddn : Contains the string to use as the _DDN (DOS (Disk Operating + System) Device Name) + - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HID + - acpi,uid : _UID value for device + - linux,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that + Linux will only load the driver if the device can be detected (e.g. on I2C + bus). Note that this is an out-of-tree Linux feature. + + +Example +------- + +elan_touchscreen: elan-touchscreen@10 { + compatible = "i2c-chip"; + reg = <0x10>; + acpi,hid = "ELAN0001"; + acpi,ddn = "ELAN Touchscreen"; + interrupts-extended = <&acpi_gpe GPIO_21_IRQ IRQ_TYPE_EDGE_FALLING>; + linux,probed; +}; From patchwork Sun Apr 26 15:19: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: 1277084 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=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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=EjQeoacu; 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 499BSw2qbkz9sRY for ; Mon, 27 Apr 2020 01:21:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3484081D36; Sun, 26 Apr 2020 17:21:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EjQeoacu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F5D881D3D; Sun, 26 Apr 2020 17:20:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 3AB4681D08 for ; Sun, 26 Apr 2020 17:20:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd42.google.com with SMTP id z2so16068388iol.11 for ; Sun, 26 Apr 2020 08:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FvO/dYqlynMt3baVgyECd1TZdlNfNKiPdXOxxDu4QnY=; b=EjQeoacuLpMpH7YHv+WyCotpDLs86x3hSIqZb1gSDRL9+ILuaCiFfRjCE68Fn1fg+Y 1AHy4xuv6mvaFxH+keGFXfPS4BVp/c0HGee6VYTfsaT/VGdHiYhcNq5f0eckAZKztoke AsqowYyC7mZSG1ji8L3vfkDwuAwX8ZZXCwc98= 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=FvO/dYqlynMt3baVgyECd1TZdlNfNKiPdXOxxDu4QnY=; b=FTEXF7TgWjLBdoi8mjzBBmeEpJiP0cCJlGBehVLVEHiPbghN8vYJ+2PJ7EnA5QwNBA QiE/hnZz1weKiRZGYcx39OPWpYbBgfKaKS0gbSuIVYCEjYyfnVg8GhqSe6AmB63dj0dU KYlss8k1jpmAs13filYG+Kyz8YaW1O97yyKKS4we2oi8gy7Dp+e3nD1pROIu3cJZ6Bvq A1/CLO0tgdI1UhYUNCQBd0sTezZHGou0fwMwPBQTyArPOjLccHRidIRU5NUpiH6VTZea kBBeJfX/2PMNHHOECdVuOYam8HipYe4I4TRj35UR/pW/jRtkikyCCrMki5IuDMStAzLo fQqg== X-Gm-Message-State: AGi0PuaNOh5KpG/gk3AfvyJ5IllQKexgRQorT78qEiRm6iq8y/OtjDmv uU8ij0FnZoMVdUbjhPAYlDHySnuldmX0Tg== X-Google-Smtp-Source: APiQypLm4NwvJ3+0Cw9A5Qvts/qLPtOd55BKHgtWbJnb6pD1XRUHFALQzs9xVI/zW9uoAvk4BdtRYw== X-Received: by 2002:a02:6983:: with SMTP id e125mr16869425jac.47.1587914398722; Sun, 26 Apr 2020 08:19:58 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:19:58 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 2/9] acpi: Add a method to write tables for a device Date: Sun, 26 Apr 2020 09:19:46 -0600 Message-Id: <20200426091948.v8.2.I04c496e973a0d5eb09ed6f6e4674c300fc34b605@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean A device may want to write out ACPI tables to describe itself to Linux. Add a method to permit this. Reviewed-by: Wolfgang Wallner Signed-off-by: Simon Glass --- Changes in v8: None Changes in v7: None Changes in v5: - Drop bisectability changes Changes in v4: - Separate out the log newline Changes in v3: None Changes in v2: - Drop definition of ACPI_TABLE_CREATOR - Make _acpi_write_dev_tables() static and switch argument order - Generalise the ACPI function recursion with acpi_recurse_method() arch/sandbox/dts/test.dts | 4 +++ arch/x86/lib/acpi_table.c | 9 ----- drivers/core/acpi.c | 62 ++++++++++++++++++++++++++++++++ include/acpi/acpi_table.h | 10 ++++++ include/dm/acpi.h | 30 ++++++++++++++++ lib/acpi/acpi_table.c | 13 +++++-- test/dm/acpi.c | 74 +++++++++++++++++++++++++++++++++++++-- 7 files changed, 187 insertions(+), 15 deletions(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index df9f1835c9..4bccfbe6e1 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -226,6 +226,10 @@ compatible = "denx,u-boot-acpi-test"; }; + acpi-test2 { + compatible = "denx,u-boot-acpi-test"; + }; + clocks { clk_fixed: clk-fixed { compatible = "fixed-clock"; diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 9346e165d8..235fc2268b 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -60,15 +60,6 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, sizeof(struct acpi_rsdp)); } -void acpi_fill_header(struct acpi_table_header *header, char *signature) -{ - memcpy(header->signature, signature, 4); - memcpy(header->oem_id, OEM_ID, 6); - memcpy(header->oem_table_id, OEM_TABLE_ID, 8); - header->oem_revision = U_BOOT_BUILD_DATE; - memcpy(header->aslc_id, ASLC_ID, 4); -} - static void acpi_write_rsdt(struct acpi_rsdt *rsdt) { struct acpi_table_header *header = &(rsdt->header); diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index ba50d688fe..e09905cf2a 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -11,8 +11,17 @@ #include #include #include +#include #include +/* Type of method to call */ +enum method_t { + METHOD_WRITE_TABLES, +}; + +/* Prototype for all methods */ +typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx); + int acpi_copy_name(char *out_name, const char *name) { strncpy(out_name, name, ACPI_NAME_LEN); @@ -31,3 +40,56 @@ int acpi_get_name(const struct udevice *dev, char *out_name) return -ENOSYS; } + +acpi_method acpi_get_method(struct udevice *dev, enum method_t method) +{ + struct acpi_ops *aops; + + aops = device_get_acpi_ops(dev); + if (aops) { + switch (method) { + case METHOD_WRITE_TABLES: + return aops->write_tables; + } + } + + return NULL; +} + +int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, + enum method_t method) +{ + struct udevice *dev; + acpi_method func; + int ret; + + func = acpi_get_method(parent, method); + if (func) { + log_debug("\n"); + log_debug("- %s %p\n", parent->name, func); + ret = device_ofdata_to_platdata(parent); + if (ret) + return log_msg_ret("ofdata", ret); + ret = func(parent, ctx); + if (ret) + return log_msg_ret("func", ret); + } + device_foreach_child(dev, parent) { + ret = acpi_recurse_method(ctx, dev, method); + if (ret) + return log_msg_ret("recurse", ret); + } + + return 0; +} + +int acpi_write_dev_tables(struct acpi_ctx *ctx) +{ + int ret; + + log_debug("Writing device tables\n"); + ret = acpi_recurse_method(ctx, dm_root(), METHOD_WRITE_TABLES); + log_debug("Writing finished, err=%d\n", ret); + + return ret; +} diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index 194be9aa58..a2bd929c92 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -505,6 +505,16 @@ int acpi_get_table_revision(enum acpi_tables table); */ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); +/** + * acpi_fill_header() - Set up a new table header + * + * This sets all fields except length, revision, checksum and aslc_revision + * + * @header: ACPI header to update + * @signature: Table signature to use (4 characters) + */ +void acpi_fill_header(struct acpi_table_header *header, char *signature); + #endif /* !__ACPI__*/ #include diff --git a/include/dm/acpi.h b/include/dm/acpi.h index 49257914ff..69d69d7f42 100644 --- a/include/dm/acpi.h +++ b/include/dm/acpi.h @@ -24,6 +24,17 @@ #if !defined(__ACPI__) +/** + * struct acpi_ctx - Context used for writing ACPI tables + * + * This contains a few useful pieces of information used when writing + * + * @current: Current address for writing + */ +struct acpi_ctx { + void *current; +}; + /** * struct acpi_ops - ACPI operations supported by driver model */ @@ -38,6 +49,15 @@ struct acpi_ops { * other error */ int (*get_name)(const struct udevice *dev, char *out_name); + + /** + * write_tables() - Write out any tables required by this device + * + * @dev: Device to write + * @ctx: ACPI context to use + * @return 0 if OK, -ve on error + */ + int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx); }; #define device_get_acpi_ops(dev) ((dev)->driver->acpi_ops) @@ -72,6 +92,16 @@ int acpi_get_name(const struct udevice *dev, char *out_name); */ int acpi_copy_name(char *out_name, const char *name); +/** + * acpi_write_dev_tables() - Write ACPI tables required by devices + * + * This scans through all devices and tells them to write any tables they want + * to write. + * + * @return 0 if OK, -ve if any device returned an error + */ +int acpi_write_dev_tables(struct acpi_ctx *ctx); + #endif /* __ACPI__ */ #endif diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 4633dcb948..372f19b16d 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -9,9 +9,8 @@ #include #include #include +#include -/* Temporary change to ensure bisectability */ -#ifndef CONFIG_SANDBOX int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) { struct acpi_table_header *header = &dmar->header; @@ -37,7 +36,6 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) return 0; } -#endif int acpi_get_table_revision(enum acpi_tables table) { @@ -91,3 +89,12 @@ int acpi_get_table_revision(enum acpi_tables table) return -EINVAL; } } + +void acpi_fill_header(struct acpi_table_header *header, char *signature) +{ + memcpy(header->signature, signature, 4); + memcpy(header->oem_id, OEM_ID, 6); + memcpy(header->oem_table_id, OEM_TABLE_ID, 8); + header->oem_revision = U_BOOT_BUILD_DATE; + memcpy(header->aslc_id, ASLC_ID, 4); +} diff --git a/test/dm/acpi.c b/test/dm/acpi.c index e7b8abd556..fb7b7e46b2 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -8,12 +8,26 @@ #include #include +#include #include #include #include #include #define ACPI_TEST_DEV_NAME "ABCD" +#define BUF_SIZE 4096 + +static int testacpi_write_tables(const struct udevice *dev, + struct acpi_ctx *ctx) +{ + struct acpi_dmar *dmar; + + dmar = (struct acpi_dmar *)ctx->current; + acpi_create_dmar(dmar, DMAR_INTR_REMAP); + ctx->current += sizeof(struct acpi_dmar); + + return 0; +} static int testacpi_get_name(const struct udevice *dev, char *out_name) { @@ -22,6 +36,7 @@ static int testacpi_get_name(const struct udevice *dev, char *out_name) struct acpi_ops testacpi_ops = { .get_name = testacpi_get_name, + .write_tables = testacpi_write_tables, }; static const struct udevice_id testacpi_ids[] = { @@ -68,8 +83,6 @@ static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) DM_TEST(dm_test_acpi_get_table_revision, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -/* Temporary change to ensure bisectability */ -#ifndef CONFIG_SANDBOX /* Test acpi_create_dmar() */ static int dm_test_acpi_create_dmar(struct unit_test_state *uts) { @@ -82,4 +95,59 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -#endif + +/* Test acpi_fill_header() */ +static int dm_test_acpi_fill_header(struct unit_test_state *uts) +{ + struct acpi_table_header hdr; + + /* Make sure these 5 fields are not changed */ + hdr.length = 0x11; + hdr.revision = 0x22; + hdr.checksum = 0x33; + hdr.aslc_revision = 0x44; + acpi_fill_header(&hdr, "ABCD"); + + ut_asserteq_mem("ABCD", hdr.signature, sizeof(hdr.signature)); + ut_asserteq(0x11, hdr.length); + ut_asserteq(0x22, hdr.revision); + ut_asserteq(0x33, hdr.checksum); + ut_asserteq_mem(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id)); + ut_asserteq_mem(OEM_TABLE_ID, hdr.oem_table_id, + sizeof(hdr.oem_table_id)); + ut_asserteq(U_BOOT_BUILD_DATE, hdr.oem_revision); + ut_asserteq_mem(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)); + ut_asserteq(0x44, hdr.aslc_revision); + + return 0; +} +DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test ACPI write_tables() */ +static int dm_test_acpi_write_tables(struct unit_test_state *uts) +{ + struct acpi_dmar *dmar; + struct acpi_ctx ctx; + void *buf; + + buf = malloc(BUF_SIZE); + ut_assertnonnull(buf); + + ctx.current = buf; + ut_assertok(acpi_write_dev_tables(&ctx)); + dmar = buf; + + /* + * We should have two dmar tables, one for each "denx,u-boot-acpi-test" + * device + */ + ut_asserteq_ptr(dmar + 2, ctx.current); + ut_asserteq(DMAR_INTR_REMAP, dmar->flags); + ut_asserteq(32 - 1, dmar->host_address_width); + + ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags); + ut_asserteq(32 - 1, dmar[1].host_address_width); + + return 0; +} +DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Sun Apr 26 15:19: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: 1277083 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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=EsziWeJV; 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 499BSj1nC2z9sRY for ; Mon, 27 Apr 2020 01:21:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EC90E81D25; Sun, 26 Apr 2020 17:20:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="EsziWeJV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D70E81D0C; Sun, 26 Apr 2020 17:20:20 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 DF10A81D0B for ; Sun, 26 Apr 2020 17:20:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd44.google.com with SMTP id e9so16080341iok.9 for ; Sun, 26 Apr 2020 08:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=npu77XNKC4MXlZtgNDjciqTQaZfHqBeXifAQut1T+Qc=; b=EsziWeJVS2vwFx3pTYEOeyTxtWoaYhbOpyQ4xGkd2+sQa6hjX8LkxPV24uUARtEzma BOJCJyQblXQqK3g1PwNyl663WHNEgSFjedyndg4h3HFgEbYgbU2CQNFwbuwfh4kMU4uh VJ6QhbCQkYsKbW+HEK4cFkNq5CfifO6Bu9I9I= 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=npu77XNKC4MXlZtgNDjciqTQaZfHqBeXifAQut1T+Qc=; b=YEyZgG7XgF8EvOoFbbuQ07h5PSeJea0T6GVfoXLKPnLut/Lq2GN74sFXxKCbiRY5T5 05TLp6YEk3QGGR4vPgv7iud80Qnw6GofU1ufqwYd6fL1C+oj/Lg/uxH7xkGhNviDi86K BLFpdaYpGW7CD5QQxJsSvfWpM8JSxyiPnQ+fYM0EF3RvUrGZeQacGGIi0EsJ0dYAEhP+ ARzj4TiGKHZGaUcXsCE4qwbll0uCYKqT2t0J7pt+c6OWxNZBTc00zXusZIOCWjGWmjmY 4xTRnWBLPI7JWnqb/69HGgRZ0XbHVOYidTMMTdDGwI23XsmMGTmglBOJB5Qg4BJjKZgP Rwmg== X-Gm-Message-State: AGi0PuZCUa++JSls8Ae9nb96SMhJCtMyCnyY7ASBQknag9OB3yq5POpj NRCFkDfSq+ruqWFK9qJ3Rt9lgqszJzytRA== X-Google-Smtp-Source: APiQypIHJtN9lsICpjNuS2Iq0D8AhjhJEF/+mqeQKELhQYs/qm+EH0MOKgwQbbFJP1Ot0u6G8wKL3w== X-Received: by 2002:a5e:8616:: with SMTP id z22mr17425521ioj.130.1587914399540; Sun, 26 Apr 2020 08:19:59 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:19:59 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 3/9] acpi: Convert part of acpi_table to use acpi_ctx Date: Sun, 26 Apr 2020 09:19:47 -0600 Message-Id: <20200426091948.v8.3.I93e1e33891714417335e1dd517982b18bf9f882f@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean The current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this would be better done in a helper function. Update write_acpi_tables() to make use of the new acpi_ctx structure, adding a few helpers to clean things up. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v8: None Changes in v7: None Changes in v5: None Changes in v4: - Update comment in acpi_inc_align() to show the alignment Changes in v3: - Rename acpi_align_large() to acpi_align64() Changes in v2: None arch/x86/lib/acpi_table.c | 88 +++++++++++++++++++-------------------- include/acpi/acpi_table.h | 36 ++++++++++++++++ lib/acpi/acpi_table.c | 24 ++++++++++- test/dm/acpi.c | 28 +++++++++++++ 4 files changed, 130 insertions(+), 46 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 235fc2268b..b73cc64339 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include /* * IASL compiles the dsdt entries and writes the hex values @@ -478,9 +480,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) /* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */ -ulong write_acpi_tables(ulong start) +ulong write_acpi_tables(ulong start_addr) { - u32 current; + struct acpi_ctx sctx, *ctx = &sctx; struct acpi_rsdp *rsdp; struct acpi_rsdt *rsdt; struct acpi_xsdt *xsdt; @@ -491,60 +493,61 @@ ulong write_acpi_tables(ulong start) struct acpi_madt *madt; struct acpi_csrt *csrt; struct acpi_spcr *spcr; + void *start; + ulong addr; int i; - current = start; + start = map_sysmem(start_addr, 0); + ctx->current = start; /* Align ACPI tables to 16 byte */ - current = ALIGN(current, 16); + acpi_align(ctx); - debug("ACPI: Writing ACPI tables at %lx\n", start); + debug("ACPI: Writing ACPI tables at %lx\n", start_addr); /* We need at least an RSDP and an RSDT Table */ - rsdp = (struct acpi_rsdp *)current; - current += sizeof(struct acpi_rsdp); - current = ALIGN(current, 16); - rsdt = (struct acpi_rsdt *)current; - current += sizeof(struct acpi_rsdt); - current = ALIGN(current, 16); - xsdt = (struct acpi_xsdt *)current; - current += sizeof(struct acpi_xsdt); + rsdp = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_rsdp)); + rsdt = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_rsdt)); + xsdt = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_xsdt)); /* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). */ - current = ALIGN(current, 64); + acpi_align64(ctx); /* clear all table memory */ - memset((void *)start, 0, current - start); + memset((void *)start, 0, ctx->current - start); acpi_write_rsdp(rsdp, rsdt, xsdt); acpi_write_rsdt(rsdt); acpi_write_xsdt(xsdt); debug("ACPI: * FACS\n"); - facs = (struct acpi_facs *)current; - current += sizeof(struct acpi_facs); - current = ALIGN(current, 16); + facs = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_facs)); acpi_create_facs(facs); debug("ACPI: * DSDT\n"); - dsdt = (struct acpi_table_header *)current; + dsdt = ctx->current; memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header)); - current += sizeof(struct acpi_table_header); - memcpy((char *)current, + acpi_inc(ctx, sizeof(struct acpi_table_header)); + memcpy(ctx->current, (char *)&AmlCode + sizeof(struct acpi_table_header), dsdt->length - sizeof(struct acpi_table_header)); - current += dsdt->length - sizeof(struct acpi_table_header); - current = ALIGN(current, 16); + acpi_inc_align(ctx, dsdt->length - sizeof(struct acpi_table_header)); /* Pack GNVS into the ACPI table area */ for (i = 0; i < dsdt->length; i++) { u32 *gnvs = (u32 *)((u32)dsdt + i); if (*gnvs == ACPI_GNVS_ADDR) { - debug("Fix up global NVS in DSDT to 0x%08x\n", current); - *gnvs = current; + ulong addr = (ulong)map_to_sysmem(ctx->current); + + debug("Fix up global NVS in DSDT to %#08lx\n", addr); + *gnvs = addr; break; } } @@ -554,51 +557,46 @@ ulong write_acpi_tables(ulong start) dsdt->checksum = table_compute_checksum((void *)dsdt, dsdt->length); /* Fill in platform-specific global NVS variables */ - acpi_create_gnvs((struct acpi_global_nvs *)current); - current += sizeof(struct acpi_global_nvs); - current = ALIGN(current, 16); + acpi_create_gnvs(ctx->current); + acpi_inc_align(ctx, sizeof(struct acpi_global_nvs)); debug("ACPI: * FADT\n"); - fadt = (struct acpi_fadt *)current; - current += sizeof(struct acpi_fadt); - current = ALIGN(current, 16); + fadt = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_fadt)); acpi_create_fadt(fadt, facs, dsdt); acpi_add_table(rsdp, fadt); debug("ACPI: * MADT\n"); - madt = (struct acpi_madt *)current; + madt = ctx->current; acpi_create_madt(madt); - current += madt->header.length; + acpi_inc_align(ctx, madt->header.length); acpi_add_table(rsdp, madt); - current = ALIGN(current, 16); debug("ACPI: * MCFG\n"); - mcfg = (struct acpi_mcfg *)current; + mcfg = ctx->current; acpi_create_mcfg(mcfg); - current += mcfg->header.length; + acpi_inc_align(ctx, mcfg->header.length); acpi_add_table(rsdp, mcfg); - current = ALIGN(current, 16); debug("ACPI: * CSRT\n"); - csrt = (struct acpi_csrt *)current; + csrt = ctx->current; acpi_create_csrt(csrt); - current += csrt->header.length; + acpi_inc_align(ctx, csrt->header.length); acpi_add_table(rsdp, csrt); - current = ALIGN(current, 16); debug("ACPI: * SPCR\n"); - spcr = (struct acpi_spcr *)current; + spcr = ctx->current; acpi_create_spcr(spcr); - current += spcr->header.length; + acpi_inc_align(ctx, spcr->header.length); acpi_add_table(rsdp, spcr); - current = ALIGN(current, 16); - debug("current = %x\n", current); + addr = map_to_sysmem(ctx->current); + debug("current = %lx\n", addr); acpi_rsdp_addr = (unsigned long)rsdp; debug("ACPI: done\n"); - return current; + return addr; } ulong acpi_get_rsdp_addr(void) diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index a2bd929c92..6fd4c5241a 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -23,6 +23,8 @@ #if !defined(__ACPI__) +struct acpi_ctx; + /* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum @@ -515,6 +517,40 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); */ void acpi_fill_header(struct acpi_table_header *header, char *signature); +/** + * acpi_align() - Align the ACPI output pointer to a 16-byte boundary + * + * @ctx: ACPI context + */ +void acpi_align(struct acpi_ctx *ctx); + +/** + * acpi_align64() - Align the ACPI output pointer to a 64-byte boundary + * + * @ctx: ACPI context + */ +void acpi_align64(struct acpi_ctx *ctx); + +/** + * acpi_inc() - Increment the ACPI output pointer by a bit + * + * The pointer is NOT aligned afterwards. + * + * @ctx: ACPI context + * @amount: Amount to increment by + */ +void acpi_inc(struct acpi_ctx *ctx, uint amount); + +/** + * acpi_inc_align() - Increment the ACPI output pointer by a bit and align + * + * The pointer is aligned afterwards to a 16-byte boundary + * + * @ctx: ACPI context + * @amount: Amount to increment by + */ +void acpi_inc_align(struct acpi_ctx *ctx, uint amount); + #endif /* !__ACPI__*/ #include diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 372f19b16d..07d9bbb0af 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -6,10 +6,11 @@ */ #include -#include #include #include #include +#include +#include int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) { @@ -98,3 +99,24 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature) header->oem_revision = U_BOOT_BUILD_DATE; memcpy(header->aslc_id, ASLC_ID, 4); } + +void acpi_align(struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN((ulong)ctx->current, 16); +} + +void acpi_align64(struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN((ulong)ctx->current, 64); +} + +void acpi_inc(struct acpi_ctx *ctx, uint amount) +{ + ctx->current += amount; +} + +void acpi_inc_align(struct acpi_ctx *ctx, uint amount) +{ + ctx->current += amount; + acpi_align(ctx); +} diff --git a/test/dm/acpi.c b/test/dm/acpi.c index fb7b7e46b2..59aee1f614 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -151,3 +151,31 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test basic ACPI functions */ +static int dm_test_acpi_basic(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + + /* Check align works */ + ctx.current = (void *)5; + acpi_align(&ctx); + ut_asserteq_ptr((void *)16, ctx.current); + + /* Check that align does nothing if already aligned */ + acpi_align(&ctx); + ut_asserteq_ptr((void *)16, ctx.current); + acpi_align64(&ctx); + ut_asserteq_ptr((void *)64, ctx.current); + acpi_align64(&ctx); + ut_asserteq_ptr((void *)64, ctx.current); + + /* Check incrementing */ + acpi_inc(&ctx, 3); + ut_asserteq_ptr((void *)67, ctx.current); + acpi_inc_align(&ctx, 3); + ut_asserteq_ptr((void *)80, ctx.current); + + return 0; +} +DM_TEST(dm_test_acpi_basic, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Sun Apr 26 15:19: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: 1277087 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=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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=ip4ePZwb; 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 499BTZ42Gpz9sSJ for ; Mon, 27 Apr 2020 01:21:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4ED6C81D44; Sun, 26 Apr 2020 17:21:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ip4ePZwb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AA51A81D35; Sun, 26 Apr 2020 17:20:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (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 B10EA81D0C for ; Sun, 26 Apr 2020 17:20:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x144.google.com with SMTP id c16so14310423ilr.3 for ; Sun, 26 Apr 2020 08:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0vLgvLWr/HgnpgBaZGARWxTmu/sY+EuxcVxZ7Qth/dg=; b=ip4ePZwbuN1lyEeLJICB/vRGoeTBfkf8YL6mnPQD05paV5HXm/qXkcUqP2fDIqCRgK C2r5TI8YE7p1cjFuQ30fgNz4l2BxMhCP3TDiQpUyvixlshvdNmF+hydEMinQLPHJa40r cYk9PlUSV4i5ljhJGVx9u6QScmICnFaBKc+2w= 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=0vLgvLWr/HgnpgBaZGARWxTmu/sY+EuxcVxZ7Qth/dg=; b=NA8goNDRltEQkrYV32+vzET5b/pi+8KfAD1ZIW1LXQ0h1TnaONFdg9qb67mzWHZ3UM nxyXGP1Tll8ZT1WTLUUeHQUCc44QySFodbE6LWxvSl+qZt+dLXFpdaMnFAt0VygDViJs LFtZ9KE5AewjaR/G3EBnBaE5WQcFGhBadiLGKedGRTss9gJaEJQuYcmLl0CgiQMyWgfK CnO9fXXkzsDLOX2I/5r8NvXMF0NjDVlH23AW6vR1yq0JaWkIsVIzzZBXXUoFlI3YLSZz zTI7dorY0EJfdkiCxmeTsIoW8UpNiPyRMsyM1028kvxGqkUOpiElY5VP3Md1sS84JABY wwcQ== X-Gm-Message-State: AGi0PuY0xj970Qaw/FT20jnvR7CiD5SCrIjf5vuUzV6+pOfcj+aX7/ia 0omQe5h1NhKG5YhTMh/K6iJoUAJILxi+yg== X-Google-Smtp-Source: APiQypL2LXsTGJwqRS2fkgCRccXdXXD5YX5+HgvQl3GZ7iURx70GRULV7zg54ogcFvxcVxPj4GQj0g== X-Received: by 2002:a92:4014:: with SMTP id n20mr17185688ila.249.1587914400420; Sun, 26 Apr 2020 08:20:00 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:20:00 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 4/9] x86: Allow devices to write ACPI tables Date: Sun, 26 Apr 2020 09:19:48 -0600 Message-Id: <20200426091948.v8.4.I6f54ae1deb9a3f954441d072e5d591d7cdb4ed5d@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Call the new core function to permit devices to write their own ACPI tables. These tables will appear after all other tables. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v8: None Changes in v7: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/x86/lib/acpi_table.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index b73cc64339..d8622da394 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -590,6 +590,8 @@ ulong write_acpi_tables(ulong start_addr) acpi_inc_align(ctx, spcr->header.length); acpi_add_table(rsdp, spcr); + acpi_write_dev_tables(ctx); + addr = map_to_sysmem(ctx->current); debug("current = %lx\n", addr); From patchwork Sun Apr 26 15:19: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: 1277082 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=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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=TaO1HGCs; 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 499BSH4mT7z9sRY for ; Mon, 27 Apr 2020 01:20:47 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 757ED81D00; Sun, 26 Apr 2020 17:20:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="TaO1HGCs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7FAA581D08; Sun, 26 Apr 2020 17:20:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 D458781D12 for ; Sun, 26 Apr 2020 17:20:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x142.google.com with SMTP id m5so6062948ilj.10 for ; Sun, 26 Apr 2020 08:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v9IAypD5CpFJ9qQVhNLf9zVbaxBgs0JxjBEmMG8T31s=; b=TaO1HGCsqvOM4qZUyBufSrGDudPrcbmqqFVYcdY9KKiWYj1rsYFvBt9kwxH1gsT01h pWmHYmiC6HVvjSoaTz+M47Mv6K0f3W40wrTS6j33snXKO92LGV95VfInOwTjT4qXYyBn cOPO5+DjMldvRuN4H5mQs4ejlM7jxwHST9aLo= 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=v9IAypD5CpFJ9qQVhNLf9zVbaxBgs0JxjBEmMG8T31s=; b=YLIR+XXLUBpeZftwkxkcPtB3/10KJ5HUGUM2HaeX9pVs3lJIb3sXRMnNDEeTGDuQvi V26IxicBSo/tOled7vrBNkcj6T/g2xC9rzA2jgn88eECgSCdBNPPmtbCGKdiNW2RrkMV 0M4NOHymJux7KSkTtCsmizIHgBPQs14p8ens5hfVZCs7oUAlOE9ye4g71RSM36hg8we4 SFHdozMz0vQnaMZFE+KSnwBAvxJSBoTpoCmU8lvORChW0Rxi7JyGDNwhzkUzt8lCMHXc h6OvzLEzIqKDM10vIEolhuO8PmY5f/08wJWv/7TO3aTb09JFZovSdKI+SBjNIBoM541y 2Xhw== X-Gm-Message-State: AGi0PuYnZt5RBTyTz530c9bNIAUykhUDpUBPVpNX92u52yHHHWKASwnV bpdRkAQcu3vRduTS8QdP6AbVTT3G1ZoAzQ== X-Google-Smtp-Source: APiQypIJq9KN7lY2XWZJm5CJUVr1+03kTcXGbpDUZGaKrBgblmfWZ0aBDPaHBJpXFEhJ4PDsW3/Rew== X-Received: by 2002:a92:dac6:: with SMTP id o6mr17345614ilq.29.1587914401254; Sun, 26 Apr 2020 08:20:01 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:20:00 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 5/9] acpi: Drop code for missing XSDT from acpi_write_rsdp() Date: Sun, 26 Apr 2020 09:19:49 -0600 Message-Id: <20200426091948.v8.5.I4566efe7db4c618499115f6973d851e0aa502da9@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean We don't actually support tables without an XSDT so we can drop this dead code. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v8: None Changes in v7: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/x86/lib/acpi_table.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index d8622da394..de1acb0ebb 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -42,19 +42,8 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, rsdp->length = sizeof(struct acpi_rsdp); rsdp->rsdt_address = (u32)rsdt; - /* - * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2 - * - * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. - * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR - * revision 0) - */ - if (xsdt == NULL) { - rsdp->revision = ACPI_RSDP_REV_ACPI_1_0; - } else { - rsdp->xsdt_address = (u64)(u32)xsdt; - rsdp->revision = ACPI_RSDP_REV_ACPI_2_0; - } + rsdp->xsdt_address = (u64)(u32)xsdt; + rsdp->revision = ACPI_RSDP_REV_ACPI_2_0; /* Calculate checksums */ rsdp->checksum = table_compute_checksum((void *)rsdp, 20); From patchwork Sun Apr 26 15:19: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: 1277085 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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=lPvsOwGf; 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 499BT700zqz9sRY for ; Mon, 27 Apr 2020 01:21:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EAD5D81D45; Sun, 26 Apr 2020 17:21:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="lPvsOwGf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C1A381D08; Sun, 26 Apr 2020 17:20:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 B064D81CFD for ; Sun, 26 Apr 2020 17:20:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd43.google.com with SMTP id o127so16125801iof.0 for ; Sun, 26 Apr 2020 08:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zeCSodtDEgx6VX6bxx0neej9Ai1wlN4MMpvuS2VJD9E=; b=lPvsOwGfE5qiIm9ZoYnnol9EpG7YXJsB1Z1+zQXQc/pPSGD84wfncJVNm8vB62b4HV ln+J8Alfu9g8vNMDifBUasOdvqsl5yYjsIxf1B4GqJ52JLTteznWI8Zmi+EjtTYeWw0Q c+NIwB8Rmodu8n/PZs4GzzoHbuYWYWmehxaKY= 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=zeCSodtDEgx6VX6bxx0neej9Ai1wlN4MMpvuS2VJD9E=; b=NgbJtzjsgFxNrhS5LleDOPgs6XXmLmOX6nzsj9AkETZBNSGGPbYGcHtF7WENlcn5in IYb8zy6kdyfmKyqlOFH79Yn4OLlcxxbHDJaxbx6jP7r4bkUU/Ohel9P6sgTFYld1HEbS C8viz78Nr6kgCssz9fSNWSLivKE1Dv+/GybrlCyfJwYS2kZkpqJV5c8T3ri+DY7ha3xC O5BV5S7pxVfrbSFcmGGznX7jZALnGklDW3P2K/oHpgAUXiYqzBxspI/OCKqh2jhMAxZ5 E54jGHHNLf5f2twzQoMlgWV1/3iz8plp8fhFmtvVaWN3kETxZkwioUKjtGstRaI94/L3 +9dA== X-Gm-Message-State: AGi0PubSReIjl/cw6pVdY7LPnCY74n6xbaimYn6jmBJSe3dOvdePqRcR xDJo9rx5kbXkyE7sLpQqkPytATSLGbU54A== X-Google-Smtp-Source: APiQypJpAWwlQ1DR8Q6Wns0ZC5WoJi4TBL1o5vqc0/jqT5rKhOS+JteCkGkjNb/aLICIemit04fgFw== X-Received: by 2002:a05:6638:62f:: with SMTP id h15mr16100247jar.102.1587914402124; Sun, 26 Apr 2020 08:20:02 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:20:01 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 6/9] acpi: Move acpi_add_table() to generic code Date: Sun, 26 Apr 2020 09:19:50 -0600 Message-Id: <20200426091948.v8.6.Ie9d79ce7293bd55022f7c6e940ce3583d38353da@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Move this code to a generic location so that we can test it with sandbox. This requires adding a few new fields to acpi_ctx, so drop the local variables used in the original code. Also use mapmem to avoid pointer-to-address casts which don't work on sandbox. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v8: - Fix tests on sandbox Changes in v7: None Changes in v5: None Changes in v4: None Changes in v3: - Fix 'RSDP' typo Changes in v2: None arch/x86/lib/acpi_table.c | 83 +++++---------------------------------- include/acpi/acpi_table.h | 9 +++++ include/dm/acpi.h | 5 +++ lib/acpi/acpi_table.c | 61 ++++++++++++++++++++++++++++ test/dm/acpi.c | 16 +++++++- 5 files changed, 100 insertions(+), 74 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index de1acb0ebb..ff8cee51d6 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -83,67 +83,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt) sizeof(struct acpi_xsdt)); } -/** - * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length - * and checksum. - */ -static void acpi_add_table(struct acpi_rsdp *rsdp, void *table) -{ - int i, entries_num; - struct acpi_rsdt *rsdt; - struct acpi_xsdt *xsdt; - - /* The RSDT is mandatory while the XSDT is not */ - rsdt = (struct acpi_rsdt *)rsdp->rsdt_address; - - /* This should always be MAX_ACPI_TABLES */ - entries_num = ARRAY_SIZE(rsdt->entry); - - for (i = 0; i < entries_num; i++) { - if (rsdt->entry[i] == 0) - break; - } - - if (i >= entries_num) { - debug("ACPI: Error: too many tables\n"); - return; - } - - /* Add table to the RSDT */ - rsdt->entry[i] = (u32)table; - - /* Fix RSDT length or the kernel will assume invalid entries */ - rsdt->header.length = sizeof(struct acpi_table_header) + - sizeof(u32) * (i + 1); - - /* Re-calculate checksum */ - rsdt->header.checksum = 0; - rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, - rsdt->header.length); - - /* The RSDT is mandatory while the XSDT is not */ - if (!rsdp->xsdt_address) - return; - - /* - * And now the same thing for the XSDT. We use the same index as for - * now we want the XSDT and RSDT to always be in sync in U-Boot - */ - xsdt = (struct acpi_xsdt *)((u32)rsdp->xsdt_address); - - /* Add table to the XSDT */ - xsdt->entry[i] = (u64)(u32)table; - - /* Fix XSDT length */ - xsdt->header.length = sizeof(struct acpi_table_header) + - sizeof(u64) * (i + 1); - - /* Re-calculate checksum */ - xsdt->header.checksum = 0; - xsdt->header.checksum = table_compute_checksum((u8 *)xsdt, - xsdt->header.length); -} - static void acpi_create_facs(struct acpi_facs *facs) { memset((void *)facs, 0, sizeof(struct acpi_facs)); @@ -472,8 +411,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) ulong write_acpi_tables(ulong start_addr) { struct acpi_ctx sctx, *ctx = &sctx; - struct acpi_rsdp *rsdp; - struct acpi_rsdt *rsdt; struct acpi_xsdt *xsdt; struct acpi_facs *facs; struct acpi_table_header *dsdt; @@ -495,9 +432,9 @@ ulong write_acpi_tables(ulong start_addr) debug("ACPI: Writing ACPI tables at %lx\n", start_addr); /* We need at least an RSDP and an RSDT Table */ - rsdp = ctx->current; + ctx->rsdp = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_rsdp)); - rsdt = ctx->current; + ctx->rsdt = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_rsdt)); xsdt = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_xsdt)); @@ -510,8 +447,8 @@ ulong write_acpi_tables(ulong start_addr) /* clear all table memory */ memset((void *)start, 0, ctx->current - start); - acpi_write_rsdp(rsdp, rsdt, xsdt); - acpi_write_rsdt(rsdt); + acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt); + acpi_write_rsdt(ctx->rsdt); acpi_write_xsdt(xsdt); debug("ACPI: * FACS\n"); @@ -553,38 +490,38 @@ ulong write_acpi_tables(ulong start_addr) fadt = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_fadt)); acpi_create_fadt(fadt, facs, dsdt); - acpi_add_table(rsdp, fadt); + acpi_add_table(ctx, fadt); debug("ACPI: * MADT\n"); madt = ctx->current; acpi_create_madt(madt); acpi_inc_align(ctx, madt->header.length); - acpi_add_table(rsdp, madt); + acpi_add_table(ctx, madt); debug("ACPI: * MCFG\n"); mcfg = ctx->current; acpi_create_mcfg(mcfg); acpi_inc_align(ctx, mcfg->header.length); - acpi_add_table(rsdp, mcfg); + acpi_add_table(ctx, mcfg); debug("ACPI: * CSRT\n"); csrt = ctx->current; acpi_create_csrt(csrt); acpi_inc_align(ctx, csrt->header.length); - acpi_add_table(rsdp, csrt); + acpi_add_table(ctx, csrt); debug("ACPI: * SPCR\n"); spcr = ctx->current; acpi_create_spcr(spcr); acpi_inc_align(ctx, spcr->header.length); - acpi_add_table(rsdp, spcr); + acpi_add_table(ctx, spcr); acpi_write_dev_tables(ctx); addr = map_to_sysmem(ctx->current); debug("current = %lx\n", addr); - acpi_rsdp_addr = (unsigned long)rsdp; + acpi_rsdp_addr = (unsigned long)ctx->rsdp; debug("ACPI: done\n"); return addr; diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index 6fd4c5241a..55349c0bb6 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -551,6 +551,15 @@ void acpi_inc(struct acpi_ctx *ctx, uint amount); */ void acpi_inc_align(struct acpi_ctx *ctx, uint amount); +/** + * acpi_add_table() - Add a new table to the RSDP and XSDT + * + * @ctx: ACPI context + * @table: Table to add + * @return 0 if OK, -E2BIG if too many tables + */ +int acpi_add_table(struct acpi_ctx *ctx, void *table); + #endif /* !__ACPI__*/ #include diff --git a/include/dm/acpi.h b/include/dm/acpi.h index 69d69d7f42..c6c63b8183 100644 --- a/include/dm/acpi.h +++ b/include/dm/acpi.h @@ -30,9 +30,14 @@ * This contains a few useful pieces of information used when writing * * @current: Current address for writing + * @rsdp: Pointer to the Root System Description Pointer, typically used when + * adding a new table. The RSDP holds pointers to the RSDT and XSDT. + * @rsdt: Pointer to the Root System Description Table */ struct acpi_ctx { void *current; + struct acpi_rsdp *rsdp; + struct acpi_rsdt *rsdt; }; /** diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 07d9bbb0af..4e354d313f 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -120,3 +122,62 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount) ctx->current += amount; acpi_align(ctx); } + +/** + * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length + * and checksum. + */ +int acpi_add_table(struct acpi_ctx *ctx, void *table) +{ + int i, entries_num; + struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; + + /* The RSDT is mandatory while the XSDT is not */ + rsdt = ctx->rsdt; + + /* This should always be MAX_ACPI_TABLES */ + entries_num = ARRAY_SIZE(rsdt->entry); + + for (i = 0; i < entries_num; i++) { + if (rsdt->entry[i] == 0) + break; + } + + if (i >= entries_num) { + log_err("ACPI: Error: too many tables\n"); + return -E2BIG; + } + + /* Add table to the RSDT */ + rsdt->entry[i] = map_to_sysmem(table); + + /* Fix RSDT length or the kernel will assume invalid entries */ + rsdt->header.length = sizeof(struct acpi_table_header) + + (sizeof(u32) * (i + 1)); + + /* Re-calculate checksum */ + rsdt->header.checksum = 0; + rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, + rsdt->header.length); + + /* + * And now the same thing for the XSDT. We use the same index as for + * now we want the XSDT and RSDT to always be in sync in U-Boot + */ + xsdt = map_sysmem(ctx->rsdp->xsdt_address, sizeof(*xsdt)); + + /* Add table to the XSDT */ + xsdt->entry[i] = map_to_sysmem(table); + + /* Fix XSDT length */ + xsdt->header.length = sizeof(struct acpi_table_header) + + (sizeof(u64) * (i + 1)); + + /* Re-calculate checksum */ + xsdt->header.checksum = 0; + xsdt->header.checksum = table_compute_checksum((u8 *)xsdt, + xsdt->header.length); + + return 0; +} diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 59aee1f614..99ae321e0a 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -21,10 +22,14 @@ static int testacpi_write_tables(const struct udevice *dev, struct acpi_ctx *ctx) { struct acpi_dmar *dmar; + int ret; dmar = (struct acpi_dmar *)ctx->current; acpi_create_dmar(dmar, DMAR_INTR_REMAP); ctx->current += sizeof(struct acpi_dmar); + ret = acpi_add_table(ctx, dmar); + if (ret) + return log_msg_ret("add", ret); return 0; } @@ -127,6 +132,7 @@ DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); static int dm_test_acpi_write_tables(struct unit_test_state *uts) { struct acpi_dmar *dmar; + struct acpi_xsdt *xsdt; struct acpi_ctx ctx; void *buf; @@ -134,8 +140,16 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) ut_assertnonnull(buf); ctx.current = buf; + ctx.rsdp = ctx.current; + acpi_inc_align(&ctx, sizeof(struct acpi_rsdp)); + ctx.rsdt = ctx.current; + acpi_inc_align(&ctx, sizeof(struct acpi_rsdt)); + xsdt = ctx.current; + acpi_inc_align(&ctx, sizeof(struct acpi_xsdt)); + ctx.rsdp->xsdt_address = map_to_sysmem(xsdt); + dmar = ctx.current; + ut_assertok(acpi_write_dev_tables(&ctx)); - dmar = buf; /* * We should have two dmar tables, one for each "denx,u-boot-acpi-test" From patchwork Sun Apr 26 15:19: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: 1277088 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=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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=js4+nvlr; 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 499BTm4BCgz9sSd for ; Mon, 27 Apr 2020 01:22:04 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CCCB881D50; Sun, 26 Apr 2020 17:21:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="js4+nvlr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0ACF81D17; Sun, 26 Apr 2020 17:20:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 CEBF981D17 for ; Sun, 26 Apr 2020 17:20:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x142.google.com with SMTP id s10so14284567iln.11 for ; Sun, 26 Apr 2020 08:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vCoalDJw3jsjpTObpLhfoNbSCqqKmYFXg1b91N3tXMg=; b=js4+nvlrAQCQ1HjfG+R4rRHs6s0ML6QeXK43hRiCGpZd4jsoYsi6IP2r0Jim3Hg9Eg gt13MyZSILHy3segyjBTDtgFf88YxLeAgxVR7UsHIe61DyPygo8fIS3Yvil9rs0gwyaz qXVksJnkb/9+Hh26s7YEsbSM8+DQ6wDrMqxT8= 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=vCoalDJw3jsjpTObpLhfoNbSCqqKmYFXg1b91N3tXMg=; b=tPCPi3a2LRWCuSKJ/pOkWFvJl0vjJkyJzhnfXf/R/IhBaDQq+h+NrMEFmq7oJShxuO ttlonhEGdyV6rI7iUKdOjn4rDzUS6jy3prE9XqStv4J4ljbmvtEU+IcoX7KH8opP902r w7DOifhdpSS4jK8BZU3Yb5nMVlN2hXh24YUXal+GnNkCFLkiBrA0mybTVYhcggn5rMlX DEPAlKOrDv8iJV2hSzhoQ9tjIDk6Ijatg+Co6KbWmHFEQW3cVaDWILIXubXr4tK3w74q PIOe8MFAOL8q+VXO2OwApcP4bX5s9gvAzSsA3WEnjo9s9Sg93OKhW//tAryJoX+wXwQc fX9Q== X-Gm-Message-State: AGi0PuboExp/UPF9t4yi7GV93WASkT2VQo+ycoKGhk8DvaMDu6atr4hn K//TMDcJKyqg5f98kETRHPB8qFca/xn78Q== X-Google-Smtp-Source: APiQypL3PTsabyWCjLaIp1WG1UGbdqsnge2v64FKXRjUfwVXcMgjK+77qjuMtVRtYJXpE3b6ZJxnDQ== X-Received: by 2002:a92:7c01:: with SMTP id x1mr16379780ilc.122.1587914403019; Sun, 26 Apr 2020 08:20:03 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:20:02 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 7/9] acpi: Put table-setup code in its own function Date: Sun, 26 Apr 2020 09:19:51 -0600 Message-Id: <20200426091948.v8.7.I34e9fcd28119cc2fcb87ad8679efb582a4c611df@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean We always write three basic tables to ACPI at the start. Move this into its own function, along with acpi_fill_header(), so we can write a test for this code. Signed-off-by: Simon Glass --- Changes in v8: - Fix test failures introduced by rebasing on top of master Changes in v7: None Changes in v5: None Changes in v4: - Put back cast on table_compute_checksum() Changes in v3: - Fix 'XDST' typo - Move acpi_align_large() out of dm_test_acpi_setup_base_tables() - Beef up the comment explaining how the unaligned address is used Changes in v2: None arch/x86/lib/acpi_table.c | 77 +----------------------------------- include/acpi/acpi_table.h | 10 +++++ lib/acpi/acpi_table.c | 82 +++++++++++++++++++++++++++++++++++++++ test/dm/acpi.c | 64 +++++++++++++++++++++++++----- 4 files changed, 147 insertions(+), 86 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index ff8cee51d6..13f1409de8 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -31,58 +31,6 @@ extern const unsigned char AmlCode[]; /* ACPI RSDP address to be used in boot parameters */ static ulong acpi_rsdp_addr; -static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, - struct acpi_xsdt *xsdt) -{ - memset(rsdp, 0, sizeof(struct acpi_rsdp)); - - memcpy(rsdp->signature, RSDP_SIG, 8); - memcpy(rsdp->oem_id, OEM_ID, 6); - - rsdp->length = sizeof(struct acpi_rsdp); - rsdp->rsdt_address = (u32)rsdt; - - rsdp->xsdt_address = (u64)(u32)xsdt; - rsdp->revision = ACPI_RSDP_REV_ACPI_2_0; - - /* Calculate checksums */ - rsdp->checksum = table_compute_checksum((void *)rsdp, 20); - rsdp->ext_checksum = table_compute_checksum((void *)rsdp, - sizeof(struct acpi_rsdp)); -} - -static void acpi_write_rsdt(struct acpi_rsdt *rsdt) -{ - struct acpi_table_header *header = &(rsdt->header); - - /* Fill out header fields */ - acpi_fill_header(header, "RSDT"); - header->length = sizeof(struct acpi_rsdt); - header->revision = 1; - - /* Entries are filled in later, we come with an empty set */ - - /* Fix checksum */ - header->checksum = table_compute_checksum((void *)rsdt, - sizeof(struct acpi_rsdt)); -} - -static void acpi_write_xsdt(struct acpi_xsdt *xsdt) -{ - struct acpi_table_header *header = &(xsdt->header); - - /* Fill out header fields */ - acpi_fill_header(header, "XSDT"); - header->length = sizeof(struct acpi_xsdt); - header->revision = 1; - - /* Entries are filled in later, we come with an empty set */ - - /* Fix checksum */ - header->checksum = table_compute_checksum((void *)xsdt, - sizeof(struct acpi_xsdt)); -} - static void acpi_create_facs(struct acpi_facs *facs) { memset((void *)facs, 0, sizeof(struct acpi_facs)); @@ -411,7 +359,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) ulong write_acpi_tables(ulong start_addr) { struct acpi_ctx sctx, *ctx = &sctx; - struct acpi_xsdt *xsdt; struct acpi_facs *facs; struct acpi_table_header *dsdt; struct acpi_fadt *fadt; @@ -424,32 +371,10 @@ ulong write_acpi_tables(ulong start_addr) int i; start = map_sysmem(start_addr, 0); - ctx->current = start; - - /* Align ACPI tables to 16 byte */ - acpi_align(ctx); debug("ACPI: Writing ACPI tables at %lx\n", start_addr); - /* We need at least an RSDP and an RSDT Table */ - ctx->rsdp = ctx->current; - acpi_inc_align(ctx, sizeof(struct acpi_rsdp)); - ctx->rsdt = ctx->current; - acpi_inc_align(ctx, sizeof(struct acpi_rsdt)); - xsdt = ctx->current; - acpi_inc_align(ctx, sizeof(struct acpi_xsdt)); - /* - * Per ACPI spec, the FACS table address must be aligned to a 64 byte - * boundary (Windows checks this, but Linux does not). - */ - acpi_align64(ctx); - - /* clear all table memory */ - memset((void *)start, 0, ctx->current - start); - - acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt); - acpi_write_rsdt(ctx->rsdt); - acpi_write_xsdt(xsdt); + acpi_setup_base_tables(ctx, start); debug("ACPI: * FACS\n"); facs = ctx->current; diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index 55349c0bb6..3681c5c8ed 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -560,6 +560,16 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount); */ int acpi_add_table(struct acpi_ctx *ctx, void *table); +/** + * acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT + * + * Set up the context with the given start position. Some basic tables are + * always needed, so set them up as well. + * + * @ctx: Context to set up + */ +void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start); + #endif /* !__ACPI__*/ #include diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 4e354d313f..59980bc0e1 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -181,3 +181,85 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table) return 0; } + +static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, + struct acpi_xsdt *xsdt) +{ + memset(rsdp, 0, sizeof(struct acpi_rsdp)); + + memcpy(rsdp->signature, RSDP_SIG, 8); + memcpy(rsdp->oem_id, OEM_ID, 6); + + rsdp->length = sizeof(struct acpi_rsdp); + rsdp->rsdt_address = map_to_sysmem(rsdt); + + rsdp->xsdt_address = map_to_sysmem(xsdt); + rsdp->revision = ACPI_RSDP_REV_ACPI_2_0; + + /* Calculate checksums */ + rsdp->checksum = table_compute_checksum(rsdp, 20); + rsdp->ext_checksum = table_compute_checksum(rsdp, + sizeof(struct acpi_rsdp)); +} + +static void acpi_write_rsdt(struct acpi_rsdt *rsdt) +{ + struct acpi_table_header *header = &rsdt->header; + + /* Fill out header fields */ + acpi_fill_header(header, "RSDT"); + header->length = sizeof(struct acpi_rsdt); + header->revision = 1; + + /* Entries are filled in later, we come with an empty set */ + + /* Fix checksum */ + header->checksum = table_compute_checksum(rsdt, + sizeof(struct acpi_rsdt)); +} + +static void acpi_write_xsdt(struct acpi_xsdt *xsdt) +{ + struct acpi_table_header *header = &xsdt->header; + + /* Fill out header fields */ + acpi_fill_header(header, "XSDT"); + header->length = sizeof(struct acpi_xsdt); + header->revision = 1; + + /* Entries are filled in later, we come with an empty set */ + + /* Fix checksum */ + header->checksum = table_compute_checksum(xsdt, + sizeof(struct acpi_xsdt)); +} + +void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start) +{ + struct acpi_xsdt *xsdt; + + ctx->current = start; + + /* Align ACPI tables to 16 byte */ + acpi_align(ctx); + + /* We need at least an RSDP and an RSDT Table */ + ctx->rsdp = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_rsdp)); + ctx->rsdt = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_rsdt)); + xsdt = ctx->current; + acpi_inc_align(ctx, sizeof(struct acpi_xsdt)); + + /* clear all table memory */ + memset((void *)start, '\0', ctx->current - start); + + acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt); + acpi_write_rsdt(ctx->rsdt); + acpi_write_xsdt(xsdt); + /* + * Per ACPI spec, the FACS table address must be aligned to a 64 byte + * boundary (Windows checks this, but Linux does not). + */ + acpi_align64(ctx); +} diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 99ae321e0a..beb1b6da73 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -8,7 +8,9 @@ #include #include +#include #include +#include #include #include #include @@ -132,23 +134,14 @@ DM_TEST(dm_test_acpi_fill_header, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); static int dm_test_acpi_write_tables(struct unit_test_state *uts) { struct acpi_dmar *dmar; - struct acpi_xsdt *xsdt; struct acpi_ctx ctx; void *buf; buf = malloc(BUF_SIZE); ut_assertnonnull(buf); - ctx.current = buf; - ctx.rsdp = ctx.current; - acpi_inc_align(&ctx, sizeof(struct acpi_rsdp)); - ctx.rsdt = ctx.current; - acpi_inc_align(&ctx, sizeof(struct acpi_rsdt)); - xsdt = ctx.current; - acpi_inc_align(&ctx, sizeof(struct acpi_xsdt)); - ctx.rsdp->xsdt_address = map_to_sysmem(xsdt); + acpi_setup_base_tables(&ctx, buf); dmar = ctx.current; - ut_assertok(acpi_write_dev_tables(&ctx)); /* @@ -162,6 +155,11 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags); ut_asserteq(32 - 1, dmar[1].host_address_width); + /* Check that the pointers were added correctly */ + ut_asserteq(map_to_sysmem(dmar), ctx.rsdt->entry[0]); + ut_asserteq(map_to_sysmem(dmar + 1), ctx.rsdt->entry[1]); + ut_asserteq(0, ctx.rsdt->entry[2]); + return 0; } DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); @@ -193,3 +191,49 @@ static int dm_test_acpi_basic(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_basic, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test acpi_setup_base_tables */ +static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) +{ + struct acpi_rsdp *rsdp; + struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; + struct acpi_ctx ctx; + void *buf, *end; + + /* + * Use an unaligned address deliberately, by allocating an aligned + * address and then adding 4 to it + */ + buf = memalign(64, BUF_SIZE); + ut_assertnonnull(buf); + acpi_setup_base_tables(&ctx, buf + 4); + + rsdp = buf + 16; + ut_asserteq_ptr(rsdp, ctx.rsdp); + ut_assertok(memcmp(RSDP_SIG, rsdp->signature, sizeof(rsdp->signature))); + ut_asserteq(sizeof(*rsdp), rsdp->length); + ut_assertok(table_compute_checksum(rsdp, 20)); + ut_assertok(table_compute_checksum(rsdp, sizeof(*rsdp))); + + rsdt = PTR_ALIGN((void *)rsdp + sizeof(*rsdp), 16); + ut_asserteq_ptr(rsdt, ctx.rsdt); + ut_assertok(memcmp("RSDT", rsdt->header.signature, ACPI_NAME_LEN)); + ut_asserteq(sizeof(*rsdt), rsdt->header.length); + ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt))); + + xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16); + ut_assertok(memcmp("XSDT", xsdt->header.signature, ACPI_NAME_LEN)); + ut_asserteq(sizeof(*xsdt), xsdt->header.length); + ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt))); + + end = PTR_ALIGN((void *)xsdt + sizeof(*xsdt), 64); + ut_asserteq_ptr(end, ctx.current); + + ut_asserteq(map_to_sysmem(rsdt), rsdp->rsdt_address); + ut_asserteq(map_to_sysmem(xsdt), rsdp->xsdt_address); + + return 0; +} +DM_TEST(dm_test_acpi_setup_base_tables, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); From patchwork Sun Apr 26 15:19: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: 1277086 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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Z03iNljk; 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 499BTM1Y4Nz9sRY for ; Mon, 27 Apr 2020 01:21:43 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F13B81D39; Sun, 26 Apr 2020 17:21:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Z03iNljk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 261C481D00; Sun, 26 Apr 2020 17:20:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 0729481D22 for ; Sun, 26 Apr 2020 17:20:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x141.google.com with SMTP id c16so14310508ilr.3 for ; Sun, 26 Apr 2020 08:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+G+KYxB4ZeRpiIi/LA8EbIABlyrPSBgvd3BaJeIG2Jo=; b=Z03iNljkNeAHEk8qY5+3sKiZDjqoHcUUUZuXjr6OlwYOMj9lhLEaOdpRaEIncrP7MK 9seOj2UE+QXEJX0SDYhjm3OaS5Pmo6JUWsVHyt2W1/r1Jl3JWILwwbaPK21Dl5dagHV+ k3WB+fErZ2RJCeb7lvcCD0MnuWMxoPMWsUqlQ= 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=+G+KYxB4ZeRpiIi/LA8EbIABlyrPSBgvd3BaJeIG2Jo=; b=nh5dW+f2uyyddxITrREOgFMQmhdFm4Sv/yV/w4DZzW/XtTXN7qcXl0UTRiQyuQrWlZ A9I6scjRwzafSdq7Ajgs5IxdoCblqToog9XPQhIPEVdllAZMpJtITah2LDyIiBW5RjZk J4wVvHQ5gTizQUPt8k7waDRlv1Bk4mbyy/IPYrkpTteYibEgLAL6KJogtRaa1d2JOJwH kt3aY6Q5BQ60IKrwoM/wrMUqlgfdgjJrZrLqVcDZRySTRIpvjYhQ2pdTQHqPP5+lo7iR FC0CFP8h7vBd03rgET1zfhuDPcPVepAprM7y9h57LWHYg8NScjtUmezjl+p2MG5xBJR+ bsEg== X-Gm-Message-State: AGi0PuZb5zMSFdneFM7J7CTk1GztlixuIm0LIjMKYlCOEnmTRbJmpDtI fAWrb1B/e1Emvh2KiQQlS2ZBUot4aqgkXQ== X-Google-Smtp-Source: APiQypJPgxWcybJpw+QgAB/YqZ53Vp8eyGTRAVSK/HtIDwNrHHRMCK86G4QV1yHXtB4EqPiFsi/4FA== X-Received: by 2002:a05:6e02:510:: with SMTP id d16mr17219203ils.3.1587914403983; Sun, 26 Apr 2020 08:20:03 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:20:03 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 8/9] acpi: Move the xsdt pointer to acpi_ctx Date: Sun, 26 Apr 2020 09:19:52 -0600 Message-Id: <20200426091948.v8.8.Ib392027f44b50a6cfdad4ce529b8479958cb302d@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Put this in the context along with the other important pointers. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v8: None Changes in v7: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None include/dm/acpi.h | 2 ++ lib/acpi/acpi_table.c | 10 ++++------ test/dm/acpi.c | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/dm/acpi.h b/include/dm/acpi.h index c6c63b8183..7563a4c60a 100644 --- a/include/dm/acpi.h +++ b/include/dm/acpi.h @@ -33,11 +33,13 @@ * @rsdp: Pointer to the Root System Description Pointer, typically used when * adding a new table. The RSDP holds pointers to the RSDT and XSDT. * @rsdt: Pointer to the Root System Description Table + * @xsdt: Pointer to the Extended System Description Table */ struct acpi_ctx { void *current; struct acpi_rsdp *rsdp; struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; }; /** diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 59980bc0e1..e86df76e2d 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -165,7 +165,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table) * And now the same thing for the XSDT. We use the same index as for * now we want the XSDT and RSDT to always be in sync in U-Boot */ - xsdt = map_sysmem(ctx->rsdp->xsdt_address, sizeof(*xsdt)); + xsdt = ctx->xsdt; /* Add table to the XSDT */ xsdt->entry[i] = map_to_sysmem(table); @@ -236,8 +236,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt) void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start) { - struct acpi_xsdt *xsdt; - ctx->current = start; /* Align ACPI tables to 16 byte */ @@ -248,15 +246,15 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start) acpi_inc_align(ctx, sizeof(struct acpi_rsdp)); ctx->rsdt = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_rsdt)); - xsdt = ctx->current; + ctx->xsdt = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_xsdt)); /* clear all table memory */ memset((void *)start, '\0', ctx->current - start); - acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt); + acpi_write_rsdp(ctx->rsdp, ctx->rsdt, ctx->xsdt); acpi_write_rsdt(ctx->rsdt); - acpi_write_xsdt(xsdt); + acpi_write_xsdt(ctx->xsdt); /* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). diff --git a/test/dm/acpi.c b/test/dm/acpi.c index beb1b6da73..a29c3cab3e 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -160,6 +160,10 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) ut_asserteq(map_to_sysmem(dmar + 1), ctx.rsdt->entry[1]); ut_asserteq(0, ctx.rsdt->entry[2]); + ut_asserteq(map_to_sysmem(dmar), ctx.xsdt->entry[0]); + ut_asserteq(map_to_sysmem(dmar + 1), ctx.xsdt->entry[1]); + ut_asserteq(0, ctx.xsdt->entry[2]); + return 0; } DM_TEST(dm_test_acpi_write_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); @@ -223,6 +227,7 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt))); xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16); + ut_asserteq_ptr(xsdt, ctx.xsdt); ut_assertok(memcmp("XSDT", xsdt->header.signature, ACPI_NAME_LEN)); ut_asserteq(sizeof(*xsdt), xsdt->header.length); ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt))); From patchwork Sun Apr 26 15:19: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: 1277089 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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=kmKHyIRO; 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 499BTy72BFz9sSJ for ; Mon, 27 Apr 2020 01:22:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CDDFD81D3C; Sun, 26 Apr 2020 17:21:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kmKHyIRO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C172781D00; Sun, 26 Apr 2020 17:20:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 6E67C81D10 for ; Sun, 26 Apr 2020 17:20:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd43.google.com with SMTP id i19so16091159ioh.12 for ; Sun, 26 Apr 2020 08:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jtTDnkpTUaoHx4MtQEe8HAVfjS6OnlFoB0yjq7CeCfI=; b=kmKHyIROSzuKF/KgnY9ECc/aZhWy/p1LUNJlbJ0WiexSGWOT/eM0k4iW9MCi88/AE5 kurFkklnDZDjJjF82s6/VscJmIS2bPA2PEOl+LMD+9I+kUabtWlpWh202McT6inKJk98 yxMHqY/kEVNTNbOdM8jfV6EKlnaokrKztcD0o= 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=jtTDnkpTUaoHx4MtQEe8HAVfjS6OnlFoB0yjq7CeCfI=; b=YgLjGdbXuhn4JAb0vt9FDmihjAOV+xnMh+Z03lb+mf8ZoDA66goug10xNUIHYKFpQL RAIras4ba6hwzz5kQM458xo6dWEVG3cOYOq+7ezQkuXGUYqy4CBxcSvLBbBp5mRa7DrR fepkfB7tXBazx09sg56UyzX8r3ZzdQkCi1jaGcFNO35IIxKkcv3oT1CTSztSVSd8O8d7 8qxyDoHQzG07EcEwl4VI9hSRUgjLc4t6k+WihLCbMYrrdUtE+goTDDpH0VvtaeSnG845 PintZPltahBl3EsH7cekoCn/+0BrlqGrxyTmOI4WEX1cf40CZppWFjtvE3aDY3de60Wz 14LQ== X-Gm-Message-State: AGi0PuYNP2tB3pwE378Gxys7fTuW9nGPj3jilLxd/6w0pTT05P92RejC XbFU6shJTzJIKTCAjZQFgori55SMp6qIIg== X-Google-Smtp-Source: APiQypKeIfA7G8syvUi92VODu6fj/EyiHw1OaCuop9lAY0XhfAoHWuZf3mUvFjhsD1bxZ6fxagVjzQ== X-Received: by 2002:a02:cebb:: with SMTP id z27mr17162156jaq.32.1587914404852; Sun, 26 Apr 2020 08:20:04 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id x11sm4402653ilm.64.2020.04.26.08.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:20:04 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Leif Lindholm , Andy Shevchenko , Wolfgang Wallner , Simon Glass Subject: [PATCH v8 9/9] acpi: Add an acpi command Date: Sun, 26 Apr 2020 09:19:53 -0600 Message-Id: <20200426091948.v8.9.I5894252b8fe4522e409528c497d882226f34ab9b@changeid> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426151953.123850-1-sjg@chromium.org> References: <20200426151953.123850-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean It is useful to dump ACPI tables in U-Boot to see what has been generated. Add a command to handle this. To allow the command to find the tables, add a position into the global data. Support subcommands to list and dump the tables. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v8: None Changes in v7: - Rebase to master Changes in v5: None Changes in v4: - Rename list_fact() to list_fadt() - Add a comment to dump_hdr() Changes in v3: None Changes in v2: None arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + cmd/Kconfig | 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 186 +++++++++++++++++++++++++ lib/acpi/acpi_table.c | 1 + test/dm/acpi.c | 73 ++++++++++ 7 files changed, 277 insertions(+) create mode 100644 cmd/acpi.c diff --git a/arch/sandbox/include/asm/global_data.h b/arch/sandbox/include/asm/global_data.h index f4ce72d566..f95ddb058a 100644 --- a/arch/sandbox/include/asm/global_data.h +++ b/arch/sandbox/include/asm/global_data.h @@ -13,6 +13,7 @@ struct arch_global_data { uint8_t *ram_buf; /* emulated RAM buffer */ void *text_base; /* pointer to base of text region */ + ulong acpi_start; /* Start address of ACPI tables */ }; #include diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h index f4c1839104..4aee2f3e8c 100644 --- a/arch/x86/include/asm/global_data.h +++ b/arch/x86/include/asm/global_data.h @@ -123,6 +123,7 @@ struct arch_global_data { #ifdef CONFIG_FSP_VERSION2 struct fsp_header *fsp_s_hdr; /* Pointer to FSP-S header */ #endif + ulong acpi_start; /* Start address of ACPI tables */ }; #endif diff --git a/cmd/Kconfig b/cmd/Kconfig index 6ce9e5521c..157a33081f 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -190,6 +190,20 @@ comment "Commands" menu "Info commands" +config CMD_ACPI + bool "acpi" + default y if ACPIGEN + help + List and dump ACPI tables. ACPI (Advanced Configuration and Power + Interface) is used mostly on x86 for providing information to the + Operating System about devices in the system. The tables are set up + by the firmware, typically U-Boot but possibly an earlier firmware + module, if U-Boot is chain-loaded from something else. ACPI tables + can also include code, to perform hardware-specific tasks required + by the Operating Systems. This allows some amount of separation + between the firmware and OS, and is particularly useful when you + want to make hardware changes without the OS needing to be adjusted. + config CMD_BDI bool "bdinfo" default y diff --git a/cmd/Makefile b/cmd/Makefile index 6692ed96c6..974ad48b0a 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -11,6 +11,7 @@ obj-y += help.o obj-y += version.o # command +obj-$(CONFIG_CMD_ACPI) += acpi.o obj-$(CONFIG_CMD_AES) += aes.o obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o diff --git a/cmd/acpi.c b/cmd/acpi.c new file mode 100644 index 0000000000..203bd93bd5 --- /dev/null +++ b/cmd/acpi.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019 Google LLC + * Written by Simon Glass + */ +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/** + * dump_hdr() - Dump an ACPI header + * + * If the header is for FACS then it shows the revision information as well + * + * @hdr: ACPI header to dump + */ +static void dump_hdr(struct acpi_table_header *hdr) +{ + bool has_hdr = memcmp(hdr->signature, "FACS", ACPI_NAME_LEN); + + printf("%.*s %08lx %06x", ACPI_NAME_LEN, hdr->signature, + (ulong)map_to_sysmem(hdr), hdr->length); + if (has_hdr) { + printf(" (v%02d %.6s %.8s %u %.4s %d)\n", hdr->revision, + hdr->oem_id, hdr->oem_table_id, hdr->oem_revision, + hdr->aslc_id, hdr->aslc_revision); + } else { + printf("\n"); + } +} + +/** + * find_table() - Look up an ACPI table + * + * @sig: Signature of table (4 characters, upper case) + * @return pointer to table header, or NULL if not found + */ +struct acpi_table_header *find_table(const char *sig) +{ + struct acpi_rsdp *rsdp; + struct acpi_rsdt *rsdt; + int len, i, count; + + rsdp = map_sysmem(gd->arch.acpi_start, 0); + if (!rsdp) + return NULL; + rsdt = map_sysmem(rsdp->rsdt_address, 0); + len = rsdt->header.length - sizeof(rsdt->header); + count = len / sizeof(u32); + for (i = 0; i < count; i++) { + struct acpi_table_header *hdr; + + hdr = map_sysmem(rsdt->entry[i], 0); + if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) + return hdr; + if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) { + struct acpi_fadt *fadt = (struct acpi_fadt *)hdr; + + if (!memcmp(sig, "DSDT", ACPI_NAME_LEN) && fadt->dsdt) + return map_sysmem(fadt->dsdt, 0); + if (!memcmp(sig, "FACS", ACPI_NAME_LEN) && + fadt->firmware_ctrl) + return map_sysmem(fadt->firmware_ctrl, 0); + } + } + + return NULL; +} + +static int dump_table_name(const char *sig) +{ + struct acpi_table_header *hdr; + + hdr = find_table(sig); + if (!hdr) + return -ENOENT; + printf("%.*s @ %08lx\n", ACPI_NAME_LEN, hdr->signature, + (ulong)map_to_sysmem(hdr)); + print_buffer(0, hdr, 1, hdr->length, 0); + + return 0; +} + +static void list_fadt(struct acpi_fadt *fadt) +{ + if (fadt->dsdt) + dump_hdr(map_sysmem(fadt->dsdt, 0)); + if (fadt->firmware_ctrl) + dump_hdr(map_sysmem(fadt->firmware_ctrl, 0)); +} + +static int list_rsdt(struct acpi_rsdt *rsdt, struct acpi_xsdt *xsdt) +{ + int len, i, count; + + dump_hdr(&rsdt->header); + if (xsdt) + dump_hdr(&xsdt->header); + len = rsdt->header.length - sizeof(rsdt->header); + count = len / sizeof(u32); + for (i = 0; i < count; i++) { + struct acpi_table_header *hdr; + + if (!rsdt->entry[i]) + break; + hdr = map_sysmem(rsdt->entry[i], 0); + dump_hdr(hdr); + if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) + list_fadt((struct acpi_fadt *)hdr); + if (xsdt) { + if (xsdt->entry[i] != rsdt->entry[i]) { + printf(" (xsdt mismatch %llx)\n", + xsdt->entry[i]); + } + } + } + + return 0; +} + +static int list_rsdp(struct acpi_rsdp *rsdp) +{ + struct acpi_rsdt *rsdt; + struct acpi_xsdt *xsdt; + + printf("RSDP %08lx %06x (v%02d %.6s)\n", (ulong)map_to_sysmem(rsdp), + rsdp->length, rsdp->revision, rsdp->oem_id); + rsdt = map_sysmem(rsdp->rsdt_address, 0); + xsdt = map_sysmem(rsdp->xsdt_address, 0); + list_rsdt(rsdt, xsdt); + + return 0; +} + +static int do_acpi_list(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct acpi_rsdp *rsdp; + + rsdp = map_sysmem(gd->arch.acpi_start, 0); + if (!rsdp) { + printf("No ACPI tables present\n"); + return 0; + } + printf("ACPI tables start at %lx\n", gd->arch.acpi_start); + list_rsdp(rsdp); + + return 0; +} + +static int do_acpi_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + const char *name; + char sig[ACPI_NAME_LEN]; + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + name = argv[1]; + if (strlen(name) != ACPI_NAME_LEN) { + printf("Table name '%s' must be four characters\n", name); + return CMD_RET_FAILURE; + } + str_to_upper(name, sig, -1); + ret = dump_table_name(sig); + if (ret) { + printf("Table '%.*s' not found\n", ACPI_NAME_LEN, sig); + return CMD_RET_FAILURE; + } + + return 0; +} + +static char acpi_help_text[] = + "list - list ACPI tables\n" + "acpi dump - Dump ACPI table"; + +U_BOOT_CMD_WITH_SUBCMDS(acpi, "ACPI tables", acpi_help_text, + U_BOOT_SUBCMD_MKENT(list, 1, 1, do_acpi_list), + U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_acpi_dump)); diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index e86df76e2d..1c253af3bf 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -240,6 +240,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start) /* Align ACPI tables to 16 byte */ acpi_align(ctx); + gd->arch.acpi_start = map_to_sysmem(ctx->current); /* We need at least an RSDP and an RSDT Table */ ctx->rsdp = ctx->current; diff --git a/test/dm/acpi.c b/test/dm/acpi.c index a29c3cab3e..176d207a55 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -7,9 +7,11 @@ */ #include +#include #include #include #include +#include #include #include #include @@ -212,6 +214,7 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) buf = memalign(64, BUF_SIZE); ut_assertnonnull(buf); acpi_setup_base_tables(&ctx, buf + 4); + ut_asserteq(map_to_sysmem(PTR_ALIGN(buf + 4, 16)), gd->arch.acpi_start); rsdp = buf + 16; ut_asserteq_ptr(rsdp, ctx.rsdp); @@ -242,3 +245,73 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_setup_base_tables, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test 'acpi list' command */ +static int dm_test_acpi_cmd_list(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + ulong addr; + void *buf; + + buf = memalign(16, BUF_SIZE); + ut_assertnonnull(buf); + acpi_setup_base_tables(&ctx, buf); + + ut_assertok(acpi_write_dev_tables(&ctx)); + + console_record_reset(); + run_command("acpi list", 0); + addr = (ulong)map_to_sysmem(buf); + ut_assert_nextline("ACPI tables start at %lx", addr); + ut_assert_nextline("RSDP %08lx %06lx (v02 U-BOOT)", addr, + sizeof(struct acpi_rsdp)); + addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16); + ut_assert_nextline("RSDT %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", + addr, sizeof(struct acpi_table_header) + + 2 * sizeof(u32), U_BOOT_BUILD_DATE); + addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16); + ut_assert_nextline("XSDT %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", + addr, sizeof(struct acpi_table_header) + + 2 * sizeof(u64), U_BOOT_BUILD_DATE); + addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64); + ut_assert_nextline("DMAR %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", + addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); + addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); + ut_assert_nextline("DMAR %08lx %06lx (v01 U-BOOT U-BOOTBL %u INTL 0)", + addr, sizeof(struct acpi_dmar), U_BOOT_BUILD_DATE); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_acpi_cmd_list, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test 'acpi dump' command */ +static int dm_test_acpi_cmd_dump(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + ulong addr; + void *buf; + + buf = memalign(16, BUF_SIZE); + ut_assertnonnull(buf); + acpi_setup_base_tables(&ctx, buf); + + ut_assertok(acpi_write_dev_tables(&ctx)); + + /* First search for a non-existent table */ + console_record_reset(); + run_command("acpi dump rdst", 0); + ut_assert_nextline("Table 'RDST' not found"); + ut_assert_console_end(); + + /* Now a real table */ + console_record_reset(); + run_command("acpi dump dmar", 0); + addr = ALIGN(map_to_sysmem(ctx.xsdt) + sizeof(struct acpi_xsdt), 64); + ut_assert_nextline("DMAR @ %08lx", addr); + ut_assert_nextlines_are_dump(0x30); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_acpi_cmd_dump, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);