From patchwork Sun May 10 20:34:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1287401 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=Gdsxdez/; 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 49Kwv52nBBz9sSc for ; Mon, 11 May 2020 06:40:49 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C7A6281C92; Sun, 10 May 2020 22:35:51 +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="Gdsxdez/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B78258180B; Sun, 10 May 2020 22:35:10 +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 9C7AF815E9 for ; Sun, 10 May 2020 22:35: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-xd44.google.com with SMTP id e9so7394384iok.9 for ; Sun, 10 May 2020 13:35: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=83gOf5SGjmoKanvYXMvA/UEh0+ArdJJDmlh6n8zVYVU=; b=Gdsxdez/OS9C9EWY1vTyBjMqgNataZFg433iYhAyX7WnSWuxxHz0wKS+fLFkbS7g2U iiVNx74hcOVprG1deI0Injv7UvlSJ5ppGTSL/FArYjOPyaULtJ77c6bPdSvY+FAeeKet N3RnKfbED+w8quDhjzJU/WpnAKO7+JgOjHTRc= 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=83gOf5SGjmoKanvYXMvA/UEh0+ArdJJDmlh6n8zVYVU=; b=eHxrGZD3om20VNcAYUjEkCM5yjy0xUPJlw7Lk7LdlN7cCbVrboR3ychay4gegluFCQ uO4uGrKzT4R/VdmKzy3iPr6KvQpQATQj+HZjyCXzdL7MegebKKGsfxFr+1cQZDy8NAZG 1pK2Xalh6jjqx+PBLPSilW7cwdcxof3wbcnZlCeTBftcOkH80YRBmGsiSn1v82KYAhWo 6I6bqcRRu/mas7tJZ4LBsa+oc+C0S9bJXTydUQCYZ17uH/y0QV7tG2rEIHA9oz5jWEQA CuGBq71HRRFssdDQjmekMkegUK0qN2U/b9nYGA3FZtWRqzvc5017xbcLJCXCOcmGToN0 XLUA== X-Gm-Message-State: AGi0PuZB0ykyXwkLDyDqJavZ5pCj5+dPr2A7ZFAYp7zkExPIvtx+WhnS IPYDHIH6cjbDMF9h1VOZfhMpUFuqx5U= X-Google-Smtp-Source: APiQypJRGJUyfO8cPeXw/uGpZJU3QsX0o1ePYSHiJwZtHoaE2jicWh/iCvHKL7A6950n5rAxzzNUpg== X-Received: by 2002:a02:2704:: with SMTP id g4mr11852194jaa.77.1589142903286; Sun, 10 May 2020 13:35: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 k2sm3607191ioq.20.2020.05.10.13.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2020 13:35:03 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Wolfgang Wallner , Bin Meng , Andy Shevchenko , Simon Glass Subject: [PATCH v2 28/35] acpi: Record the items added to SSDT Date: Sun, 10 May 2020 14:34:02 -0600 Message-Id: <20200510143320.v2.28.I1f119e7a847da3e0b2b1791e6f48acaeaf25a223@changeid> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200510203409.203520-1-sjg@chromium.org> References: <20200510203409.203520-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 be able to control the order of data written to the SSDT so that we can compare the output against known-good kernel dumps. Add code to record each item that is added along with the device that added it. That allows us to reorder things later if needed. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v2: None Changes in v1: - Generalise the ACPI function recursion with acpi_recurse_method() drivers/core/acpi.c | 83 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 4497b5cb2f..fa16be8154 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -9,12 +9,21 @@ #define LOG_CATEOGRY LOGC_ACPI #include +#include #include #include #include #include #include +#define MAX_ITEMS 100 + +/* Type of table that we collected */ +enum gen_type_t { + TYPE_NONE, + TYPE_SSDT, +}; + /* Type of method to call */ enum method_t { METHOD_WRITE_TABLES, @@ -24,6 +33,25 @@ enum method_t { /* Prototype for all methods */ typedef int (*acpi_method)(const struct udevice *dev, struct acpi_ctx *ctx); +/** + * struct acpi_item - Holds info about ACPI data generated by a driver method + * + * @dev: Device that generated this data + * @type: Table type it refers to + * @buf: Buffer containing the data + * @size: Size of the data in bytes + */ +struct acpi_item { + struct udevice *dev; + enum gen_type_t type; + char *buf; + int size; +}; + +/* List of ACPI items collected */ +static struct acpi_item acpi_item[MAX_ITEMS]; +static int item_count; + int acpi_copy_name(char *out_name, const char *name) { strncpy(out_name, name, ACPI_NAME_LEN); @@ -43,6 +71,43 @@ int acpi_get_name(const struct udevice *dev, char *out_name) return -ENOSYS; } +/** + * acpi_add_item() - Add a new item to the list of data collected + * + * @ctx: ACPI context + * @dev: Device that generated the data + * @type: Table type it refers to + * @start: The start of the data (the end is obtained from ctx->current) + * @return 0 if OK, -ENOSPC if too many items, -ENOMEM if out of memory + */ +static int acpi_add_item(struct acpi_ctx *ctx, struct udevice *dev, + enum gen_type_t type, void *start) +{ + struct acpi_item *item; + void *end = ctx->current; + + if (item_count == MAX_ITEMS) { + log_err("Too many items\n"); + return log_msg_ret("mem", -ENOSPC); + } + + item = &acpi_item[item_count]; + item->dev = dev; + item->type = type; + item->size = end - start; + if (!item->size) + return 0; + item->buf = malloc(item->size); + if (!item->buf) + return log_msg_ret("mem", -ENOMEM); + memcpy(item->buf, start, item->size); + item_count++; + log_debug("* %s: Added type %d, %p, size %x\n", dev->name, type, start, + item->size); + + return 0; +} + acpi_method acpi_get_method(struct udevice *dev, enum method_t method) { struct acpi_ops *aops; @@ -61,7 +126,7 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method) } int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, - enum method_t method) + enum method_t method, enum gen_type_t type) { struct udevice *dev; acpi_method func; @@ -69,6 +134,8 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, func = acpi_get_method(parent, method); if (func) { + void *start = ctx->current; + log_debug("\n"); log_debug("- %s %p\n", parent->name, func); ret = device_ofdata_to_platdata(parent); @@ -77,9 +144,16 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, ret = func(parent, ctx); if (ret) return log_msg_ret("func", ret); + + /* Add the item to the internal list */ + if (type != TYPE_NONE) { + ret = acpi_add_item(ctx, parent, type, start); + if (ret) + return log_msg_ret("add", ret); + } } device_foreach_child(dev, parent) { - ret = acpi_recurse_method(ctx, dev, method); + ret = acpi_recurse_method(ctx, dev, method, type); if (ret) return log_msg_ret("recurse", ret); } @@ -92,7 +166,7 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx) int ret; log_debug("Writing SSDT tables\n"); - ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SSDT); + ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_SSDT, TYPE_SSDT); log_debug("Writing SSDT finished, err=%d\n", ret); return ret; @@ -103,7 +177,8 @@ 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); + ret = acpi_recurse_method(ctx, dm_root(), METHOD_WRITE_TABLES, + TYPE_NONE); log_debug("Writing finished, err=%d\n", ret); return ret;