Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7FA4CE7AB8 for ; Fri, 6 Sep 2024 07:24:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EFDFE88D42; Fri, 6 Sep 2024 09:22:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=9elements.com header.i=@9elements.com header.b="Zr4uWWAr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 54C4088D50; Fri, 6 Sep 2024 09:22:52 +0200 (CEST) Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 1F05088D40 for ; Fri, 6 Sep 2024 09:22:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.rudolph@9elements.com Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8a1acb51a7so194809366b.2 for ; Fri, 06 Sep 2024 00:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1725607367; x=1726212167; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qmuBfCWB4jiMoMxQZK+tkyV3Wa7C0zap8rVKh+dF9JI=; b=Zr4uWWArrieGFgfUFcBzCmLXHt7hVf7uVOwT6gg7y638ACpy2fjPu4U+AwSbHLHbAO AxiiQbQGp+lInjROhqnm4MRFRvGbcKWFd/KKqYtREP0iBA1DtA6mURSg8//HT+sCiLH0 Rdqo7ftFTj1DvJdtBRVIzHlojUOwQlw02Wl+Xxiu5e7l5juPGP2NrHLjRqc+2v9KKru/ k+yJrn7yrKHzy4R1i0i8zZB440QuUmCBWMxfNud4AJDDynLrySkNPd7D68lkZpqdB7UQ 3cHBXqBiIoD+NtccpNKA9eKr7/mKfMFEs77/m3SFPVorrvgQvBZ1sVwBLZxWKeRMCQVO Yu3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725607367; x=1726212167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qmuBfCWB4jiMoMxQZK+tkyV3Wa7C0zap8rVKh+dF9JI=; b=nsjaZJs0mauPA2NzrbaREwy/vDhXHAZsMBmWP1G51ZJ3IRy0aA8FuM2xgRHmeAOpTc qygo37dj42R0UI98DGmC7Fz+/52R7/8zNzjtc/EAo1AUD4pM2npt9dB95zNaWfLBW7Fh BGgINaxTLgIFmUm4kx7Wk6g5pGUbMAl0VMB1YBvb5952Ozm7Zk+OEQG3VmTLyyZPqAyO Q3gbI4duWMbXCTO4FiejQ3l9EMqRgdqBeRASQX3D3g1Nr/dbx6uU+oVhjx0ZYHOS9aAD gZa5qY2CL/qbTf8HHz4fmGbLr4qjPKAz3XRLpRZdWDOmmo78RY/QSutFfIn3TnrCz8Dd r/iw== X-Gm-Message-State: AOJu0YwfwwEfoTr2hgQHVASGbHJxh7YTMXLN966ijezMbfQ53mMf2UqJ nRRcYK4q4h7bG4f9WgDICqXI/sHokQ8W2UeJOpwneNXdjweS8QP1dlurGmK7lLyXRChid21spyd s X-Google-Smtp-Source: AGHT+IFLSPjdvodNFsVJJme39ncpbYdpZdYSfihRUfz6ClGlM5BVU+KKAQlJUSjXMjKpX+R+7oROOw== X-Received: by 2002:a17:907:9411:b0:a89:d1cd:1936 with SMTP id a640c23a62f3a-a8a885bff8fmr120932966b.3.1725607367517; Fri, 06 Sep 2024 00:22:47 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a7f7f541csm107748466b.193.2024.09.06.00.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 00:22:47 -0700 (PDT) From: Patrick Rudolph To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, sr@denx.de, pbrobinson@gmail.com, mbrugger@suse.com, maximilian.brune@9elements.com, Patrick Rudolph Subject: [PATCH v2 13/28] acpi: acpi_table: Support ACPI 2.0 platforms Date: Fri, 6 Sep 2024 09:22:15 +0200 Message-ID: <20240906072231.2531491-14-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240906072231.2531491-1-patrick.rudolph@9elements.com> References: <20240906072231.2531491-1-patrick.rudolph@9elements.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean On platforms that do not have usable DRAM below 4GiB, like QEMU sbsa, the RSDT cannot be used. Allow both RSDT and XSDT to be null and only fill those tables that are present in acpi_add_table(). Fixes a crash on QEMU sbsa. Signed-off-by: Patrick Rudolph Cc: Simon Glass Cc: Tom Rini --- lib/acpi/acpi_table.c | 95 ++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index bdd7b6b066..c2b8b24f1f 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -157,51 +157,70 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table) 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; - } + /* On legacy x86 platforms the RSDT is mandatory while the XSDT is not. + * On other platforms there might be no memory below 4GiB, thus RSDT is NULL. + */ + if (ctx->rsdt) { + rsdt = ctx->rsdt; - /* Add table to the RSDT */ - rsdt->entry[i] = nomap_to_sysmem(table); + /* This should always be MAX_ACPI_TABLES */ + entries_num = ARRAY_SIZE(rsdt->entry); - /* Fix RSDT length or the kernel will assume invalid entries */ - rsdt->header.length = sizeof(struct acpi_table_header) + - (sizeof(u32) * (i + 1)); + for (i = 0; i < entries_num; i++) { + if (rsdt->entry[i] == 0) + break; + } - /* Re-calculate checksum */ - rsdt->header.checksum = 0; - rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, - rsdt->header.length); + if (i >= entries_num) { + log_err("ACPI: Error: too many tables\n"); + return -E2BIG; + } - /* - * 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 = ctx->xsdt; + /* Add table to the RSDT */ + rsdt->entry[i] = nomap_to_sysmem(table); - /* Add table to the XSDT */ - xsdt->entry[i] = nomap_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)); - /* Fix XSDT length */ - xsdt->header.length = sizeof(struct acpi_table_header) + - (sizeof(u64) * (i + 1)); + /* Re-calculate checksum */ + rsdt->header.checksum = 0; + rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, + rsdt->header.length); + } - /* Re-calculate checksum */ - xsdt->header.checksum = 0; - xsdt->header.checksum = table_compute_checksum((u8 *)xsdt, - xsdt->header.length); + if (ctx->xsdt) { + /* + * 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 = ctx->xsdt; + + /* This should always be MAX_ACPI_TABLES */ + entries_num = ARRAY_SIZE(xsdt->entry); + + for (i = 0; i < entries_num; i++) { + if (xsdt->entry[i] == 0) + break; + } + + if (i >= entries_num) { + log_err("ACPI: Error: too many tables\n"); + return -E2BIG; + } + + /* Add table to the XSDT */ + xsdt->entry[i] = nomap_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; } -- 2.45.2