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 7D86FC001DB for ; Mon, 14 Aug 2023 13:21:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5195D86918; Mon, 14 Aug 2023 15:21:13 +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="kNUndiIu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 90AD380753; Mon, 14 Aug 2023 15:21:11 +0200 (CEST) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 7FCD2807B4 for ; Mon, 14 Aug 2023 15:21:09 +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-xd30.google.com with SMTP id ca18e2360f4ac-7909307ecd1so152840039f.1 for ; Mon, 14 Aug 2023 06:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692019268; x=1692624068; 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=porreGpknkhixhtBGfU6+P8wZqiPFVBjrG47/t7mAzM=; b=kNUndiIu5fJEzMb2LaHkIKDkMMjS0c7PnY+G3TDenIz0azuV/VjA8NmhUqJA4lGHBi MeS68TYpcyH6TJFe/wRvlw6V5/9doTcVfytnNV/EVwjVav1cLMzF8Z8oob8UYyXnV3zv 7gHf+nWUGBLtHfh4nuMN4/stj6CFlYRTKI6us= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692019268; x=1692624068; 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=porreGpknkhixhtBGfU6+P8wZqiPFVBjrG47/t7mAzM=; b=k70OdAccGuKajcRRE0y+10YzNtvwhi5CkUvQcGvgcKfGWr42AkpFEaToMgPa/5lIyJ BgOJQjUHeW8aLSjp8V2un/VMBT1OEndmynlfVuVyqvjFYR2fBzqCTLpfI9R27RxeKB7h oVG/jlBCyVo2Ns0xJpSKrZlbYmWpByaOj61+sIV1MJX5S5XUWXHIk8oaAg+et+cdAcuu zF8MRE4wePQsyNVriBI4DFICMkrBvNlPZe3yLYMXqo2TjHZwE6IMWe75euXhTi6tG8rF keB6PRMJAgWk3klDAyPQAXYpQ+Uz3PaS1g1GYfviIVB9uYKXwj0gTkF+oSHT/lBhOIUd xjQg== X-Gm-Message-State: AOJu0YwUt21WLoI8bkyjYahUTVjZOPOmHJjOcPycR5MoyVNwIP5rjzEJ XPdkNSAwKbQkRmFsWKwX+8UvLIQ8MVt6eT2Sd0w= X-Google-Smtp-Source: AGHT+IGKHkhESGZAn7JpGV91oZQDUoq/o+0zsH7LPeffFlaBPKVRxn4I9s5siZa1XWilT8Bit+WJaQ== X-Received: by 2002:a5d:89d2:0:b0:790:fc0f:4005 with SMTP id a18-20020a5d89d2000000b00790fc0f4005mr13026152iot.20.1692019268145; Mon, 14 Aug 2023 06:21:08 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id x12-20020a02970c000000b0042b76deb22fsm2956202jai.92.2023.08.14.06.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:21:07 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Alex Sadovsky , Simon Glass , Bin Meng , Paul Menzel , Coreboot ML , Jean-Marie Lemetayer , Jonas Karlman , Konrad Dybcio , Peng Fan , Vladimir Zapolskiy Subject: [PATCH v2 2/2] x86: Update cbmem driver Date: Mon, 14 Aug 2023 07:20:44 -0600 Message-ID: <20230814132059.496023-2-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230814132059.496023-1-sjg@chromium.org> References: <20230814132059.496023-1-sjg@chromium.org> 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 This driver is not actually built since a Kconfig was never created for it. Add a Kconfig (which is already implied by COREBOOT) and update the implementation to avoid using unnecessary memory. Drop the #ifdef at the top since we can rely on Kconfig to get that right. To enable it (in addition to serial and video), use: setenv stdout serial,vidconsole,cbmem Signed-off-by: Simon Glass --- Changes in v2: - Update to support the new overflow mechanism drivers/misc/Kconfig | 8 ++++++++ drivers/misc/cbmem_console.c | 38 +++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index b9f5c7a37aed..3df57a5bfbd9 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -122,6 +122,14 @@ config VEXPRESS_CONFIG configuration bus on the Arm Versatile Express boards via a sysreg driver. +config CBMEM_CONSOLE + bool "Write console output to coreboot cbmem" + depends on X86 + help + Enables console output to the cbmem console, which is a memory + region set up by coreboot to hold a record of all console output. + Enable this only if booting from coreboot. + config CMD_CROS_EC bool "Enable crosec command" depends on CROS_EC diff --git a/drivers/misc/cbmem_console.c b/drivers/misc/cbmem_console.c index 8bbe33d414da..7a47a814f638 100644 --- a/drivers/misc/cbmem_console.c +++ b/drivers/misc/cbmem_console.c @@ -5,27 +5,30 @@ #include #include -#ifndef CONFIG_SYS_COREBOOT -#error This driver requires coreboot -#endif - #include -struct cbmem_console { - u32 buffer_size; - u32 buffer_cursor; - u8 buffer_body[0]; -} __attribute__ ((__packed__)); - -static struct cbmem_console *cbmem_console_p; - void cbmemc_putc(struct stdio_dev *dev, char data) { - int cursor; - - cursor = cbmem_console_p->buffer_cursor++; - if (cursor < cbmem_console_p->buffer_size) - cbmem_console_p->buffer_body[cursor] = data; + const struct sysinfo_t *sysinfo = cb_get_sysinfo(); + struct cbmem_console *cons; + uint pos, flags; + + if (!sysinfo) + return; + cons = sysinfo->cbmem_cons; + if (!cons) + return; + + pos = cons->cursor & CBMC_CURSOR_MASK; + flags = cons->cursor & ~CBMC_CURSOR_MASK; + + cons->body[pos++] = data; + if (pos >= cons->size) { + pos = 0; + flags |= CBMC_OVERFLOW; + } + + cons->cursor = flags | pos; } void cbmemc_puts(struct stdio_dev *dev, const char *str) @@ -40,7 +43,6 @@ int cbmemc_init(void) { int rc; struct stdio_dev cons_dev; - cbmem_console_p = lib_sysinfo.cbmem_cons; memset(&cons_dev, 0, sizeof(cons_dev)); -- 2.41.0.640.ga95def55d0-goog