From patchwork Sat Sep 12 18:28:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1362899 X-Patchwork-Delegate: trini@ti.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=GcCQ0EXm; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Bph443RBtz9sTK for ; Sun, 13 Sep 2020 04:29:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 13EBE822DF; Sat, 12 Sep 2020 20:29:06 +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="GcCQ0EXm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71EA0822DF; Sat, 12 Sep 2020 20:29:00 +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-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 6300482242 for ; Sat, 12 Sep 2020 20:28:57 +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-x143.google.com with SMTP id s88so1671259ilb.6 for ; Sat, 12 Sep 2020 11:28:57 -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=K/Xsc4o4SJ6dmK3Zlm088PBITvioR2lp0xTdau2WWeE=; b=GcCQ0EXmoZR//iZ0reRt3BPKxnIyyJS4XSCqswiy60VrnW1yE2O8q0zXWkY63kKdtP C3L6EtGQ5Ax5U3FAj2thKmKasM7dHtnLVPXJCexHI8aqHJHwAGrWR9/Yi2hlPaK9nKm0 fbsMQpWmvaDJR6nB3YRedvmLB0ctKI7PAC/zU= 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=K/Xsc4o4SJ6dmK3Zlm088PBITvioR2lp0xTdau2WWeE=; b=gnk4uxo50lInQHDk/kVKE5AHYTQoty8E+T2mo8Ih7FbwVBPCJKezPG8Qr0wy+RmVaR hb3/7rqpS+nZGZKy2ByqJFI2BbIaoZq+NNJfmtdBiU5i37UkgYK6cZx+rxVl/KL51To4 hxUuTOfL6qdXZoVxHOQttrSymO5njq/Z5Jh3m3jOFOtESsf/k0iGu1zkEHZVBwGDsPs4 fhchq1y8GrOuk67HmzxJi5AiKuqo54NsFWVD7F/dZmFFD/koIqu/OfUg/fkMP9IKOOZI FMu5n6oWHdIpsFuwRprRlNoBqL/Djgo6CJ7YpYiZ8rOZxUJmJiyF+G3pJr47FUeEhvoU m4lQ== X-Gm-Message-State: AOAM533d+QgDILyxUnJYUAV7R/CEZBWDI+mK8quOyeaRqnYCvRLlspgB NRbMvUicGtTngCG1S8ZFIGk3so85KXO477Eu X-Google-Smtp-Source: ABdhPJwilvCdQOYC6/udC13p5CtqcrOSIQj2snWl9UsEUjHi0GYj8nqh7BTB5MQdBPhgyTDGMjzzGA== X-Received: by 2002:a05:6e02:1031:: with SMTP id o17mr6380091ilj.47.1599935336196; Sat, 12 Sep 2020 11:28:56 -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 v24sm3134212ioh.21.2020.09.12.11.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 11:28:55 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Simon Glass , Andy Shevchenko , Bin Meng , Sean Anderson Subject: [PATCH 3/4] log: Add a way to enable/disable a log device Date: Sat, 12 Sep 2020 12:28:49 -0600 Message-Id: <20200912122845.3.I3743cdceacc4e8d4046331664ff17066779b9fd9@changeid> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200912182850.3909182-1-sjg@chromium.org> References: <20200912182850.3909182-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 At present all log devices are enabled by default. Add a function to allow devices to be disabled or enabled at runtime. Signed-off-by: Simon Glass --- common/log.c | 38 ++++++++++++++++++++++++++++++++++++++ include/log.h | 17 +++++++++++++++++ test/log/log_test.c | 7 +++++++ test/py/tests/test_log.py | 8 ++++++++ 4 files changed, 70 insertions(+) diff --git a/common/log.c b/common/log.c index ce528fe4535..a9aacfaf354 100644 --- a/common/log.c +++ b/common/log.c @@ -297,6 +297,44 @@ int log_remove_filter(const char *drv_name, int filter_num) return -ENOENT; } +/** + * log_find_device_by_drv() - Find a device by its driver + * + * @drv: Log driver + * @return Device associated with that driver, or NULL if not found + */ +static struct log_device *log_find_device_by_drv(struct log_driver *drv) +{ + struct log_device *ldev; + + list_for_each_entry(ldev, &gd->log_head, sibling_node) { + if (ldev->drv == drv) + return ldev; + } + /* + * It is quite hard to pass an invalid driver since passing an unknown + * LOG_GET_DRIVER(xxx) would normally produce a compilation error. But + * it is possible to pass NULL, for example, so this + */ + + return NULL; +} + +int log_device_set_enable(struct log_driver *drv, bool enable) +{ + struct log_device *ldev; + + ldev = log_find_device_by_drv(drv); + if (!ldev) + return -ENOENT; + if (enable) + ldev->flags |= LOGDF_ENABLE; + else + ldev->flags &= ~LOGDF_ENABLE; + + return 0; +} + int log_init(void) { struct log_driver *drv = ll_entry_start(struct log_driver, log_driver); diff --git a/include/log.h b/include/log.h index d28bc1ef0e4..4acc087b2e9 100644 --- a/include/log.h +++ b/include/log.h @@ -388,6 +388,10 @@ struct log_filter { #define LOG_DRIVER(_name) \ ll_entry_declare(struct log_driver, _name, log_driver) +/* Get a pointer to a given driver */ +#define LOG_GET_DRIVER(__name) \ + ll_entry_get(struct log_driver, __name, log_driver) + /** * log_get_cat_name() - Get the name of a category * @@ -465,6 +469,19 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[], */ int log_remove_filter(const char *drv_name, int filter_num); +/** + * log_device_set_enable() - Enable or disable a log device + * + * Devices are referenced by their driver, so use LOG_GET_DRIVER(name) to pass + * the driver to this function. For example if the driver is declared with + * LOG_DRIVER(wibble) then pass LOG_GET_DRIVER(wibble) here. + * + * @drv: Driver of device to enable + * @enable: true to enable, false to disable + * @return 0 if OK, -ENOENT if the driver was not found + */ +int log_device_set_enable(struct log_driver *drv, bool enable); + #if CONFIG_IS_ENABLED(LOG) /** * log_init() - Set up the log system ready for use diff --git a/test/log/log_test.c b/test/log/log_test.c index fdee5e6757f..6a60ff6be3c 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -196,6 +196,13 @@ static int log_test(int testnum) log_io("level %d\n", LOGL_DEBUG_IO); break; } + case 11: + log_err("default\n"); + ret = log_device_set_enable(LOG_GET_DRIVER(console), false); + log_err("disabled\n"); + ret = log_device_set_enable(LOG_GET_DRIVER(console), true); + log_err("enabled\n"); + break; } return 0; diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index ddc28f19ee8..275f9382d2f 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -92,6 +92,13 @@ def test_log(u_boot_console): for i in range(7): assert 'log_test() level %d' % i == next(lines) + def test11(): + """Test use of log_device_set_enable()""" + lines = run_test(11) + assert 'log_test() default' + # disabled should not be displayed + assert 'log_test() enabled' + # TODO(sjg@chromium.org): Consider structuring this as separate tests cons = u_boot_console test0() @@ -105,6 +112,7 @@ def test_log(u_boot_console): test8() test9() test10() + test11() @pytest.mark.buildconfigspec('cmd_log') def test_log_format(u_boot_console):