From patchwork Sun Apr 26 15:25:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1277108 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=hSWuHte2; 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 499Bgb4hy3z9sRY for ; Mon, 27 Apr 2020 01:30:35 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7A7D881D53; Sun, 26 Apr 2020 17:29:34 +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="hSWuHte2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BE37281D6C; Sun, 26 Apr 2020 17:26:58 +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 520EF81D43 for ; Sun, 26 Apr 2020 17:26:40 +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 i16so14305470ils.12 for ; Sun, 26 Apr 2020 08:26:40 -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=EG8RLgc4IrRYaTQ3NGi560Y8FnRUO9qfsyBHldhOsqg=; b=hSWuHte2guMeUgWcY8HK1KNzENlYLtt156O57sTxD8LYljex/v6Nr2/mmHTgRxZzBW jb6nfPbIe65k28STOne9DP+OjBGH3u721ZifKbAuoeyDfeS4q7kIHoUjRbL35GgU3gVa sdtlwWG38b+WYV1S+Q3Gfh3RZuXWppVR9AFzY= 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=EG8RLgc4IrRYaTQ3NGi560Y8FnRUO9qfsyBHldhOsqg=; b=bdxjoedTzQhiLOL9aNB8ovqVhMwJW1jNPW7XoqTQbRZ13BoUmHE8az7gSu76WoqSLt eOvZSsvufv8tj0hKZaOBNMh4fyUOcnC1QUAqAkU4ECb6pJGhkuN9d/9GxqZZYhpn6RMF /DPwxTX4EQ32nfBW47n31Qp8YqFj+06ruZimnS5tPAqiMItbBINEipEa/84sPZ3PRnWy Ph3HuDEp5fodFx/zS7iXdGQJe2aw8hWcLnumBEbJA4TzvSy+8uhj3QXycFLKbQkePzhh Y+QSfbE+TKMS13P0BT1/rXfHXBoHGX23KGANXTkbYgg5pdHyjvdpyL0P3lbirHJ/m9Kr 57JQ== X-Gm-Message-State: AGi0PuZCG2NRF47Tc3XBTnKfSme2Ex4ebxp3wwCQvIMT3QzMvoRdgCk4 +WiPZ0utzMN7WXnS1Jdf6t/x4+Lyvxp+LQ== X-Google-Smtp-Source: APiQypKcO+TtYpf0b1CmJCIatiF8+pRauRw9eH7ln6z4gxyHQF+cDJPpWw8lA+d7r1UJNaLgngQjgw== X-Received: by 2002:a92:4989:: with SMTP id k9mr647273ilg.104.1587914798977; Sun, 26 Apr 2020 08:26:38 -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 r16sm4437069ilb.32.2020.04.26.08.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 08:26:38 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Wolfgang Wallner , Bin Meng , Andy Shevchenko , Simon Glass Subject: [PATCH v8 16/35] acpi: Support writing a string Date: Sun, 26 Apr 2020 09:25:59 -0600 Message-Id: <20200426152618.125646-14-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog In-Reply-To: <20200426152618.125646-1-sjg@chromium.org> References: <20200426152618.125646-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 ACPI supports storing a simple nul-terminated string. Add support for this. Signed-off-by: Simon Glass --- Changes in v8: None Changes in v3: None Changes in v2: None include/acpi/acpigen.h | 10 ++++++++++ lib/acpi/acpigen.c | 6 ++++++ test/dm/acpigen.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/acpi/acpigen.h b/include/acpi/acpigen.h index a4edcb097b..f65de53a76 100644 --- a/include/acpi/acpigen.h +++ b/include/acpi/acpigen.h @@ -21,6 +21,7 @@ enum { BYTE_PREFIX = 0x0a, WORD_PREFIX = 0x0b, DWORD_PREFIX = 0x0c, + STRING_PREFIX = 0x0d, QWORD_PREFIX = 0x0e, PACKAGE_OP = 0x12, }; @@ -147,4 +148,13 @@ char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el); */ void acpigen_write_integer(struct acpi_ctx *ctx, u64 data); +/** + * acpigen_write_string() - Write a string + * + * This writes a STRING_PREFIX followed by a nul-terminated string + * + * @ctx: ACPI context pointer + * @str: String to write + */ +void acpigen_write_string(struct acpi_ctx *ctx, const char *str); #endif diff --git a/lib/acpi/acpigen.c b/lib/acpi/acpigen.c index 01222533f2..275293d22c 100644 --- a/lib/acpi/acpigen.c +++ b/lib/acpi/acpigen.c @@ -145,3 +145,9 @@ void acpigen_emit_string(struct acpi_ctx *ctx, const char *str) acpigen_emit_stream(ctx, str, str ? strlen(str) : 0); acpigen_emit_byte(ctx, '\0'); /* NUL */ } + +void acpigen_write_string(struct acpi_ctx *ctx, const char *str) +{ + acpigen_emit_byte(ctx, STRING_PREFIX); + acpigen_emit_string(ctx, str); +} diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c index 9350943a12..dc6993b7a7 100644 --- a/test/dm/acpigen.c +++ b/test/dm/acpigen.c @@ -20,6 +20,7 @@ #include #define TEST_STRING "frogmore" +#define TEST_STRING2 "ranch" #define TEST_STREAM2 "\xfa\xde" #define TEST_INT8 0x7d @@ -400,7 +401,7 @@ static int dm_test_acpi_len(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_len, 0); -/* Test emitting a package */ +/* Test writing a package */ static int dm_test_acpi_package(struct unit_test_state *uts) { struct acpi_ctx *ctx; @@ -427,7 +428,7 @@ static int dm_test_acpi_package(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_package, 0); -/* Test emitting an integer */ +/* Test writing an integer */ static int dm_test_acpi_integer(struct unit_test_state *uts) { struct acpi_ctx *ctx; @@ -467,3 +468,30 @@ static int dm_test_acpi_integer(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_integer, 0); + +/* Test writing a string */ +static int dm_test_acpi_string(struct unit_test_state *uts) +{ + struct acpi_ctx *ctx; + u8 *ptr; + + ut_assertok(alloc_context(&ctx)); + + ptr = acpigen_get_current(ctx); + + acpigen_write_string(ctx, TEST_STRING); + acpigen_write_string(ctx, TEST_STRING2); + + ut_asserteq(2 + sizeof(TEST_STRING) + sizeof(TEST_STRING2), + acpigen_get_current(ctx) - ptr); + ut_asserteq(STRING_PREFIX, ptr[0]); + ut_asserteq_str(TEST_STRING, (char *)ptr + 1); + ptr += 1 + sizeof(TEST_STRING); + ut_asserteq(STRING_PREFIX, ptr[0]); + ut_asserteq_str(TEST_STRING2, (char *)ptr + 1); + + free_context(&ctx); + + return 0; +} +DM_TEST(dm_test_acpi_string, 0);