From patchwork Tue Sep 3 10:12:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11127639 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2484315E9 for ; Tue, 3 Sep 2019 10:13:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C95F21883 for ; Tue, 3 Sep 2019 10:13:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C95F21883 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C33989812; Tue, 3 Sep 2019 10:12:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id 528FC897FF for ; Tue, 3 Sep 2019 10:12:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E07B67EB89; Tue, 3 Sep 2019 10:12:52 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-72.ams2.redhat.com [10.36.117.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DE26196AE; Tue, 3 Sep 2019 10:12:49 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 164CD31F38; Tue, 3 Sep 2019 12:12:49 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/6] drm: add drm_print_bits Date: Tue, 3 Sep 2019 12:12:43 +0200 Message-Id: <20190903101248.12879-2-kraxel@redhat.com> In-Reply-To: <20190903101248.12879-1-kraxel@redhat.com> References: <20190903101248.12879-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Tue, 03 Sep 2019 10:12:53 +0000 (UTC) X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , open list , David Airlie , Gerd Hoffmann , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" New helper to print named bits of some value (think flags fields). Signed-off-by: Gerd Hoffmann --- include/drm/drm_print.h | 3 +++ drivers/gpu/drm/drm_print.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index a5d6f2f3e430..8658c1da1c7d 100644 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -88,6 +88,9 @@ __printf(2, 3) void drm_printf(struct drm_printer *p, const char *f, ...); void drm_puts(struct drm_printer *p, const char *str); void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset); +void drm_print_bits(struct drm_printer *p, unsigned int indent, + const char *label, unsigned int value, + const char *bits[], unsigned int nbits); __printf(2, 0) /** diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index a17c8a14dba4..7f7aba920f51 100644 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -179,6 +179,42 @@ void drm_printf(struct drm_printer *p, const char *f, ...) } EXPORT_SYMBOL(drm_printf); +/** + * drm_print_bits - print bits to a &drm_printer stream + * + * Print bits (in flag fields for example) in human readable form. + * + * @p: the &drm_printer + * @indent: Tab indentation level (max 5) + * @label: field label. + * @value: field value. + * @bits: Array with bit names. + * @nbits: bit name array size. + */ +void drm_print_bits(struct drm_printer *p, unsigned int indent, + const char *label, unsigned int value, + const char *bits[], unsigned int nbits) +{ + bool first = true; + unsigned int i; + + for (i = 0; i < nbits; i++) { + if (!(value & (1 << i))) + continue; + if (!bits[i]) + continue; + if (first) { + first = false; + drm_printf_indent(p, indent, "%s=%s", + label, bits[i]); + } else + drm_printf(p, ",%s", bits[i]); + } + if (!first) + drm_printf(p, "\n"); +} +EXPORT_SYMBOL(drm_print_bits); + void drm_dev_printk(const struct device *dev, const char *level, const char *format, ...) {