Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp281923ybe; Tue, 3 Sep 2019 22:49:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1T0yfWJuyhWdc6iG0v2xV8A3SOBNIftoM030/rouAzsc3zPxSlqQWHDnUigYl3fCu4+ke X-Received: by 2002:a17:902:6a82:: with SMTP id n2mr37102230plk.53.1567576142615; Tue, 03 Sep 2019 22:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567576142; cv=none; d=google.com; s=arc-20160816; b=eOj9GzERK7Z8KuZM//aVBIiwGxBn/cd47BBvPQvJPr3Lhu2zWG5pqhMswVLJzuSIsL hqvSUzOUXMDhQZYyfesHeiF6k4oV0tlQgIG/Y40gf39oUw72QeJqgmmk8Nw5MhS/wwka HOI6QbDqaFf2AbZ9V/oZVXpPbrQrJktAtNcjT6jGfIH4LZ7bBVuUuTIgS5+iG8CRCdOV Njqs9UzdI0v5p3gf/TCpvSJ0Q02JOvCbLfwfoXk9MGqss3LkDSdELa5fbFtfnTy3lqjY ZE5q6gRvkKm0WsF1EywNsj1mIBRbUQsmGDvqgUB2AIIwgG8yYrntmu/+mlfYISTz0Glp th9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=i5HkUe54k4EZ7NsBTLpMd0rnCfxxrYjl+aNazG1O48w=; b=Hlson2+7cMusgrAzsA4ptzrQkCF7seCBwjwfTMHivNyP66+rdS/IjgpZOaKAY+4Dle dom0PpWwoOQIH5siwBXppUotAjWnvUf3peuikM5aWNTVsXScisJEDKre20qVsKi86hmo Rv1z9716Dp8LrL1WnnLbHerqIwRQaauaIeWwf+KyqeYsSVIRgvUDGXqNBzXEXzPx3BxK jFeSGmiIHsVxGFJZADVDUCWOV5Sb/N6atBM3TkY/r07Ix/AcBYLfioZEHsOxcSh0XtWi iKrqFIx40KAR3UWDUpbuJ9g+A/AJlznrR8J+2VsqiHmVlV5hyKUdE2CZvQAFyiWfMfum dZ9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3si16578615plq.143.2019.09.03.22.48.47; Tue, 03 Sep 2019 22:49:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728327AbfIDFrp (ORCPT + 99 others); Wed, 4 Sep 2019 01:47:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46126 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725938AbfIDFrp (ORCPT ); Wed, 4 Sep 2019 01:47:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F23FE10C6973; Wed, 4 Sep 2019 05:47:44 +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 1319B6092D; Wed, 4 Sep 2019 05:47:42 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CA12831E8D; Wed, 4 Sep 2019 07:47:40 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: Gerd Hoffmann , Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 1/7] drm: add drm_print_bits Date: Wed, 4 Sep 2019 07:47:34 +0200 Message-Id: <20190904054740.20817-2-kraxel@redhat.com> In-Reply-To: <20190904054740.20817-1-kraxel@redhat.com> References: <20190904054740.20817-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Wed, 04 Sep 2019 05:47:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h index 112165d3195d..12d4916254b4 100644 --- a/include/drm/drm_print.h +++ b/include/drm/drm_print.h @@ -89,6 +89,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 long value, const char *bits[], + unsigned int from, unsigned int to); __printf(2, 0) /** diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index ad302d71eeee..dfa27367ebb8 100644 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -185,6 +185,39 @@ 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. + * The first name in the @bits array is for the bit indexed by @from. + * + * @p: the &drm_printer + * @value: field value. + * @bits: Array with bit names. + * @from: start of bit range to print (inclusive). + * @to: end of bit range to print (exclusive). + */ +void drm_print_bits(struct drm_printer *p, + unsigned long value, const char *bits[], + unsigned int from, unsigned int to) +{ + bool first = true; + unsigned int i; + + for (i = from; i < to; i++) { + if (!(value & (1 << i))) + continue; + if (WARN_ON_ONCE(!bits[i-from])) + continue; + drm_printf(p, "%s%s", first ? "" : ",", + bits[i-from]); + first = false; + } + if (first) + drm_printf(p, "(none)"); +} +EXPORT_SYMBOL(drm_print_bits); + void drm_dev_printk(const struct device *dev, const char *level, const char *format, ...) { -- 2.18.1