From patchwork Thu Oct 22 03:02: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: 1385885 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=f929WlQt; 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 4CGskD1VR9z9sSn for ; Thu, 22 Oct 2020 14:08:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 25770824C7; Thu, 22 Oct 2020 05:04: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="f929WlQt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A43DF82479; Thu, 22 Oct 2020 05:03:48 +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 ADCAE82441 for ; Thu, 22 Oct 2020 05:03: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=sjg@chromium.org Received: by mail-io1-xd44.google.com with SMTP id b8so12668ioh.11 for ; Wed, 21 Oct 2020 20:03:44 -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=iStFcUfARlNif/m0sgdnwX7AcVDfeTVsbbUFReLMZaI=; b=f929WlQt5LV1Vzumz5lsfbDVP9dZFvgvuaSaO+rPsoB2RF477YVlMclNSZIYq+IvPI CEIWhNYYHrpnfKnA40nyRLbg8spWJeRRDaUjjpTSuDdN0Ari3K0L7d1zBXsYg37rUq2x lOFaUSCLscgx+CO5IlRNdnnsFatXqEfaS2Qfw= 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=iStFcUfARlNif/m0sgdnwX7AcVDfeTVsbbUFReLMZaI=; b=ZmazLRMPyOOa50A7PDt2cqjrA+rTVCkv1IqS662kzXsMEt/a826qfWm35dedUteYA1 +JCM/yONGrSz+5QdFv2hTQgOjwwgKQBWBAtNyZKb6kQnGsAPQcG/av1p613dUzD/wdGT ByZ54lcEAcXM0m/msXd6Esv+lWp6HGW+v/JuodMao2kTxVvfIhrsYzaGjRs0Lg+XGoU8 KV0LDVHN5LZB25eC5Q7AXE/blR5v1ma3Cwypifjek2Hm96/aQITDMPGxtQZr1p/gS2+4 XC1asqiGd+jxjwryp1FseWaNwcE5xIYTgyBY8o1g6Vk+PrE/EmIRd8Jy2NjMiFqZ7K7c 5VjA== X-Gm-Message-State: AOAM533lCE/yRhIJgdBWqXZ9HARP+Te8FvVv/LXJjQ9eco/ldFQeufBJ LgCCNTVuuJulCDZcyHCVyKbxcHKq1GFaO2L5 X-Google-Smtp-Source: ABdhPJyMZRX3tUxVTN0W7zKr/RNPbTVpuwzUGcBBz0TpxSUfYKrWGsu8hvbs9P7eG+EnsQJlNLVcIQ== X-Received: by 2002:a5d:84c6:: with SMTP id z6mr438040ior.0.1603335823427; Wed, 21 Oct 2020 20:03:43 -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 p4sm206171ilg.79.2020.10.21.20.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 20:03:42 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Bernhard Messerklinger , Wolfgang Wallner , Walter Lozano , Simon Glass , Bin Meng Subject: [PATCH v2 19/30] x86: acpi: Put the generated code first in DSDT Date: Wed, 21 Oct 2020 21:02:52 -0600 Message-Id: <20201022030303.584490-18-sjg@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022030303.584490-1-sjg@chromium.org> References: <20201022030303.584490-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.3 at phobos.denx.de X-Virus-Status: Clean The current implementation for DSDT tables is not correct for the case where there is generated code, as the length ends up being incorrect. Also, we want the generated code to go first in the table. Rewrite this piece to correct these problems. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- (no changes since v1) arch/x86/lib/acpi_table.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index c5c5c6e6794..423df5cbf9b 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -505,6 +505,7 @@ static int acpi_create_ssdt(struct acpi_ctx *ctx, */ ulong write_acpi_tables(ulong start_addr) { + const int thl = sizeof(struct acpi_table_header); struct acpi_ctx *ctx; struct acpi_facs *facs; struct acpi_table_header *dsdt; @@ -516,6 +517,7 @@ ulong write_acpi_tables(ulong start_addr) struct acpi_csrt *csrt; struct acpi_spcr *spcr; void *start; + int aml_len; ulong addr; int ret; int i; @@ -541,21 +543,28 @@ ulong write_acpi_tables(ulong start_addr) dsdt = ctx->current; /* Put the table header first */ - memcpy(dsdt, &AmlCode, sizeof(struct acpi_table_header)); - acpi_inc(ctx, sizeof(struct acpi_table_header)); + memcpy(dsdt, &AmlCode, thl); + acpi_inc(ctx, thl); + log_debug("DSDT starts at %p, hdr ends at %p\n", dsdt, ctx->current); /* If the table is not empty, allow devices to inject things */ - if (dsdt->length >= sizeof(struct acpi_table_header)) - acpi_inject_dsdt(ctx); + aml_len = dsdt->length - thl; + if (aml_len) { + void *base = ctx->current; - /* Copy in the AML code itself if any (after the header) */ - memcpy(ctx->current, - (char *)&AmlCode + sizeof(struct acpi_table_header), - dsdt->length - sizeof(struct acpi_table_header)); + acpi_inject_dsdt(ctx); + log_debug("Added %x bytes from inject_dsdt, now at %p\n", + ctx->current - base, ctx->current); + log_debug("Copy AML code size %x to %p\n", aml_len, + ctx->current); + memcpy(ctx->current, AmlCode + thl, aml_len); + acpi_inc(ctx, aml_len); + } - acpi_inc(ctx, dsdt->length - sizeof(struct acpi_table_header)); dsdt->length = ctx->current - (void *)dsdt; acpi_align(ctx); + log_debug("Updated DSDT length to %x, total %x\n", dsdt->length, + ctx->current - (void *)dsdt); if (!IS_ENABLED(CONFIG_ACPI_GNVS_EXTERNAL)) { /* Pack GNVS into the ACPI table area */