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 26950EE01F3 for ; Wed, 11 Sep 2024 06:27:01 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 71B2C89179; Wed, 11 Sep 2024 08:25:35 +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="KN+Smsd0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6E89F8918C; Wed, 11 Sep 2024 08:25:34 +0200 (CEST) Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (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 5D23089187 for ; Wed, 11 Sep 2024 08:25:32 +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-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c3d20eed0bso1836233a12.0 for ; Tue, 10 Sep 2024 23:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1726035932; x=1726640732; 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=a2XnXmr5VVEYohapwzn9ACKuhmZzWCvEcx8Tjp3UpJs=; b=KN+Smsd0lplFjl7pEyBQsN5kNPZi0iKa41MaHWagyM5C5KHEEWpvIDnIMmadhgaKbO PCz8cXmEheHmDfk6UzIb691S6kdvoTGhZQHV2d8s23HSAJrtJHSbKEFDva5KLBom5zKa D8eWbHr9OkJDNws+Spdzj6WxaUopT+yh1ooRQL+WW7gPU1u46CLunEpNpfiWP0VSdmjr 7cEY/TWXf9CneXNvebcrkdvc6QY8B8OBne67GvYkY2yzuL8tQdjUgaNDXIu4va5KLAC6 hTCeq61wINHEwwWE2+aErLL4+6lEAXkCsqOayWsQJa5qIvcfi1KDzGFDG5I7wykuMgES IL9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726035932; x=1726640732; 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=a2XnXmr5VVEYohapwzn9ACKuhmZzWCvEcx8Tjp3UpJs=; b=P3RS1oTRS+LaIFFih/cqVINFzxkpQY+/btnPAMopShPHZ9IaBcyrWpYsNlsj4K5+/e 456WO4WFjzBw94axr8uyeMPiOuR97z2FumLd/gVubMSw6/Bm+wF/l1ctvbXS+8qHbUV4 BpcdkekZMD+NUD+wA6dBPLODbNLKxVxeBUdEmCkOIUeVspPO0FQhg2vnXzQcGvRak+Xm oqh6H7ZOtvztCIhyoMMgIF7004IvY7Je2EWd53v3XEtm9sUHoXeU1QT8JIkpb+t6WkUz dPPq2D2iTSctWXVQkyOH5sLezSyOROVhAWQjNMJAPu5c9sS7pLOXYaOer3QR9H4Rg5Cj hRqw== X-Gm-Message-State: AOJu0Yyo7yR2w52UrwAZxUsLOtMfHwYLCMzUqoADIPrKK9etLwzcNDd4 +6/damnbiYAaKronKO2yOX4gpkty6Xxe/Wurc3RGwpCAl5DbOPlMqcBPVl3Ph6NVeRacty0LfSW 7 X-Google-Smtp-Source: AGHT+IH1guB5YzL+MzfEEXYXKHkhVYFhAaGXrNtTyYm9N0x7I5T5l1X7x7MYLWhKIt7iDo261ISOFw== X-Received: by 2002:a17:907:3e13:b0:a7a:9fe9:99e7 with SMTP id a640c23a62f3a-a9004a46e96mr162531766b.41.1726035931709; Tue, 10 Sep 2024 23:25:31 -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-a8d25a43365sm575545366b.94.2024.09.10.23.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 23:25:31 -0700 (PDT) From: Patrick Rudolph To: u-boot@lists.denx.de, Simon Glass Cc: Patrick Rudolph , Tom Rini Subject: [PATCH v3 08/30] acpi: Add fill_madt to acpi_ops Date: Wed, 11 Sep 2024 08:23:58 +0200 Message-ID: <20240911062511.494855-9-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911062511.494855-1-patrick.rudolph@9elements.com> References: <20240911062511.494855-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 Add a new method to acpi_ops to let drivers fill out ACPI MADT. The code is unused for now until drivers implement the new ops. TEST: Booted on QEMU sbsa using driver model generated MADT. Signed-off-by: Patrick Rudolph Cc: Simon Glass --- arch/arm/lib/acpi_table.c | 7 +++++++ drivers/core/acpi.c | 16 +++++++++++++++ include/dm/acpi.h | 26 ++++++++++++++++++++++++ lib/acpi/acpi_table.c | 2 +- test/dm/acpi.c | 42 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) diff --git a/arch/arm/lib/acpi_table.c b/arch/arm/lib/acpi_table.c index db6e40bdef..8c17e9eb36 100644 --- a/arch/arm/lib/acpi_table.c +++ b/arch/arm/lib/acpi_table.c @@ -112,3 +112,10 @@ int acpi_pptt_add_cache(struct acpi_ctx *ctx, const u32 flags, return offset; } + +__weak void *acpi_fill_madt(struct acpi_madt *madt, struct acpi_ctx *ctx) +{ + /* TODO: Drop __weak once all SoCs are migrated to driver model */ + acpi_fill_madt_subtbl(ctx); + return ctx->current; +} diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 9f78422892..4763963914 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -48,6 +48,7 @@ enum method_t { METHOD_FILL_SSDT, METHOD_INJECT_DSDT, METHOD_SETUP_NHLT, + METHOD_FILL_MADT, }; /* Prototype for all methods */ @@ -282,6 +283,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method) switch (method) { case METHOD_WRITE_TABLES: return aops->write_tables; + case METHOD_FILL_MADT: + return aops->fill_madt; case METHOD_FILL_SSDT: return aops->fill_ssdt; case METHOD_INJECT_DSDT: @@ -328,6 +331,19 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, return 0; } +int acpi_fill_madt_subtbl(struct acpi_ctx *ctx) +{ + int ret; + + log_debug("Writing MADT table\n"); + ret = acpi_recurse_method(ctx, dm_root(), METHOD_FILL_MADT, TYPE_NONE); + log_debug("Writing MADT finished, err=%d\n", ret); + if (ret) + return log_msg_ret("build", ret); + + return ret; +} + int acpi_fill_ssdt(struct acpi_ctx *ctx) { void *start = ctx->current; diff --git a/include/dm/acpi.h b/include/dm/acpi.h index 3adfe21767..d6bc0c099a 100644 --- a/include/dm/acpi.h +++ b/include/dm/acpi.h @@ -146,6 +146,22 @@ struct acpi_ops { */ int (*write_tables)(const struct udevice *dev, struct acpi_ctx *ctx); + /** + * fill_madt() - Generate MADT sub-tables for a device + * + * This is called to create the MADT table. The method should write out + * whatever sub-table is needed by this device. It will end up in the + * MADT table. + * + * Note that this is called 'fill' because the entire contents of the + * MADT is build by calling this method on all devices. + * + * @dev: Device to write + * @ctx: ACPI context to use + * @return 0 if OK, -ve on error + */ + int (*fill_madt)(const struct udevice *dev, struct acpi_ctx *ctx); + /** * fill_ssdt() - Generate SSDT code for a device * @@ -231,6 +247,16 @@ int acpi_copy_name(char *out_name, const char *name); */ int acpi_write_dev_tables(struct acpi_ctx *ctx); +/** + * acpi_fill_madt_subtbl() - Generate ACPI tables for MADT + * + * This is called to create the MADT sub-tables for all devices. + * + * @ctx: ACPI context to use + * Return: 0 if OK, -ve on error + */ +int acpi_fill_madt_subtbl(struct acpi_ctx *ctx); + /** * acpi_fill_ssdt() - Generate ACPI tables for SSDT * diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index d7deed2df1..96ca3b05a0 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -261,11 +261,11 @@ int acpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry) header->revision = ACPI_MADT_REV_ACPI_3_0; acpi_inc(ctx, sizeof(struct acpi_madt)); + /* TODO: Get rid of acpi_fill_madt and use driver model */ current = acpi_fill_madt(madt, ctx); /* (Re)calculate length and checksum */ header->length = (uintptr_t)current - (uintptr_t)madt; - header->checksum = table_compute_checksum((void *)madt, header->length); acpi_add_table(ctx, madt); ctx->current = (void *)madt + madt->header.length; diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 7da381f1a5..cc032a4618 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -95,6 +95,21 @@ static int testacpi_get_name(const struct udevice *dev, char *out_name) return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME); } +static int testacpi_fill_madt(const struct udevice *dev, struct acpi_ctx *ctx) +{ + u64 *data = ctx->current; + + /* Only fill madt once */ + if (device_get_uclass_id(dev->parent) != UCLASS_TEST_ACPI) + return 0; + + *data = 0xdeadbeef; + + acpi_inc(ctx, sizeof(u64)); + + return 0; +} + static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx) { const char *data; @@ -124,6 +139,7 @@ static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx *ctx) struct acpi_ops testacpi_ops = { .get_name = testacpi_get_name, .write_tables = testacpi_write_tables, + .fill_madt = testacpi_fill_madt, .fill_ssdt = testacpi_fill_ssdt, .inject_dsdt = testacpi_inject_dsdt, }; @@ -532,6 +548,32 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_fill_ssdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +/* Test acpi_fill_madt() */ +static int dm_test_acpi_fill_madt(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + u64 *buf; + + buf = malloc(BUF_SIZE); + ut_assertnonnull(buf); + + acpi_reset_items(); + ctx.current = buf; + buf[1] = 'z'; /* sentinel */ + ut_assertok(acpi_fill_madt_subtbl(&ctx)); + + /* + * These values come from acpi-test2's acpi-ssdt-test-data property. + * This device comes first because of u-boot,acpi-ssdt-order + */ + ut_asserteq(0xdeadbeef, buf[0]); + + ut_asserteq('z', buf[1]); + + return 0; +} +DM_TEST(dm_test_acpi_fill_madt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + /* Test acpi_inject_dsdt() */ static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts) { -- 2.46.0