Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4489851rdh; Wed, 29 Nov 2023 03:02:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjibE7EMIe/+NFlyVnfSLd9YRhY2Mcw3GE4D8cs9CNKmlA4WBzRFCxKZscDbVvVAB5pNdt X-Received: by 2002:a05:6a20:6a0e:b0:18b:8158:b115 with SMTP id p14-20020a056a206a0e00b0018b8158b115mr20754506pzk.56.1701255754092; Wed, 29 Nov 2023 03:02:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701255754; cv=none; d=google.com; s=arc-20160816; b=kgSAea4/AW06+mPIZ9x/4cf+EBraYlzzI5PuQlqv6bMxPOyGZaUbKx+wxgJTFlVcJh Lp1O+hMLb5Lziwn+jD/Fuga3iSvx7zppn9zHErEADrqfEfPBeyKDHVDb7bpEMqvsq7ql ms8+H/kcX9by8NsgbvCoKSE9Kq0WM9JsuGTWIOCkHrPLmoC4/L9HJXQD8N7gc2UFSZLc bmI4nVrCIyA1X6G9cjTPlxwEBWGU6etkObA9oC8A32ut8Gs2NsJnhhudJpMz10rnlUnE qOu9FUidHaV7wnXeR+nc6OkouvhJAwAVoAatU+gpenZ/O+511A6mGHCrl8hqGdF7ITHt i0Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=qloskjrwtuPE6VP0GC2+1BXZ0ggKNy5+XtXZM5+19pE=; fh=OIGwdmvqc16swakll8QclR/tIMfddQXy4C6CPb3sT38=; b=mKcVh7+6UaHYW0N1Wf0qYz4vSVHiZqCBMSyqv+sQDPti5PAibFGykG7zQHMrZDVrP/ Q9o+Mb8mJduEEfbC/7//psGF0AbL8GiOOUH6YopjLIrH+F2LtRCWj/et78gX8E55EpJ5 ckxmE6sgKgIz8syWrXKPhApQT/bOHgUg5fm9yUvHILdmvhdWsQJLg26r2CXDkO5SdbYt 2j12fmlosbJ8hxxlGvYAHSl2NbX/IbXw/0yTUe2soqFqBmsV3JVJn+GuTcfI7gZWFAih CAJ9mibv8l8briM+KpDvyz6YV6ZoZiWAqWb3S6WEtYtpZLEdu0Q7ZryGlfwzUIgy1WYq Of/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rock-chips.com header.s=default header.b=a9ITbs8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f23-20020a635117000000b0055b640a6b3csi14003106pgb.884.2023.11.29.03.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:02:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@rock-chips.com header.s=default header.b=a9ITbs8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9D12A8076020; Wed, 29 Nov 2023 03:02:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbjK2LCL (ORCPT + 99 others); Wed, 29 Nov 2023 06:02:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjK2LCJ (ORCPT ); Wed, 29 Nov 2023 06:02:09 -0500 Received: from mail-m118211.qiye.163.com (mail-m118211.qiye.163.com [115.236.118.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42CD9C1; Wed, 29 Nov 2023 03:02:14 -0800 (PST) DKIM-Signature: a=rsa-sha256; b=a9ITbs8TfaeIhTYttP9xzfL8ZO9RQ0QXTF9ludK6vwEfB1Sit32UEtAF4UhpPuHR9CRLNF4DWcRoCu97mg6/FKIoZrEnlUSX+jLsOe0jOAimEWCpi8juoWTTeIEuMvWvGYw/JMWyL9d6f5xddxJ4mT0TWn+ACq2WP5BlWRp+Ajk=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=qloskjrwtuPE6VP0GC2+1BXZ0ggKNy5+XtXZM5+19pE=; h=date:mime-version:subject:message-id:from; Received: from [172.16.12.141] (unknown [58.22.7.114]) by mail-m12779.qiye.163.com (Hmail) with ESMTPA id 50CCE780223; Wed, 29 Nov 2023 19:01:38 +0800 (CST) Message-ID: <13a58162-6708-498c-84bd-68a1e814f30b@rock-chips.com> Date: Wed, 29 Nov 2023 19:01:37 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 11/12] drm/rockchip: vop2: Add debugfs support To: Sascha Hauer Cc: Andy Yan , heiko@sntech.de, hjc@rock-chips.com, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, devicetree@vger.kernel.org, sebastian.reichel@collabora.com, kever.yang@rock-chips.com, chris.obbard@collabora.com References: <20231122125316.3454268-1-andyshrk@163.com> <20231122125601.3455031-1-andyshrk@163.com> <20231127101337.GU3359458@pengutronix.de> <20231129085229.GC963049@pengutronix.de> Content-Language: en-US From: Andy Yan In-Reply-To: <20231129085229.GC963049@pengutronix.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQx1PTVZCTk9MTh1MGUNNHUxVEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSk5MSUpJVUpLS1VKQl kG X-HM-Tid: 0a8c1abdd8cab24fkuuu50cce780223 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MSo6CBw6KDw1LBMQHxRLAgE5 DytPCiNVSlVKTEtKSU5OTUJCSExJVTMWGhIXVRoVHwJVAhoVOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBSk5JQ0w3Bg++ X-Spam-Status: No, score=0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:02:30 -0800 (PST) Hi Sascha: On 11/29/23 16:52, Sascha Hauer wrote: > On Mon, Nov 27, 2023 at 06:56:34PM +0800, Andy Yan wrote: >> Hi Sascha: >> >> thanks for you review. >> >> On 11/27/23 18:13, Sascha Hauer wrote: >> >> On Wed, Nov 22, 2023 at 08:56:01PM +0800, Andy Yan wrote: >> >> From: Andy Yan [1] >> >> /sys/kernel/debug/dri/vop2/summary: dump vop display state >> /sys/kernel/debug/dri/vop2/regs: dump whole vop registers >> /sys/kernel/debug/dri/vop2/active_regs: only dump the registers of >> activated modules >> >> Signed-off-by: Andy Yan [2] >> --- >> >> (no changes since v1) >> >> drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 399 +++++++++++++++++++ >> 1 file changed, 399 insertions(+) >> >> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c >> index 9eecbe1f71f9..4a2342209c15 100644 >> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c >> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c >> @@ -27,6 +27,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> >> @@ -187,6 +188,7 @@ struct vop2 { >> */ >> u32 registered_num_wins; >> >> + struct resource *res; >> void __iomem *regs; >> struct regmap *map; >> >> @@ -228,6 +230,44 @@ struct vop2 { >> #define vop2_output_if_is_lvds(x) (x == ROCKCHIP_VOP2_EP_LVDS0 || x == ROCKCHIP_VOP2_EP_LVDS1) >> #define vop2_output_if_is_dpi(x) (x == ROCKCHIP_VOP2_EP_RGB0) >> >> +struct vop2_regs_dump { >> + const char *name; >> + u32 base; >> + u32 en_reg; >> + u32 en_val; >> + u32 en_mask; >> +}; >> + >> +/* >> + * bus-format types. >> + */ >> +struct drm_bus_format_enum_list { >> + int type; >> + const char *name; >> +}; >> + >> +static const struct drm_bus_format_enum_list drm_bus_format_enum_list[] = { >> + { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, >> + { MEDIA_BUS_FMT_RGB565_1X16, "RGB565_1X16" }, >> + { MEDIA_BUS_FMT_RGB666_1X18, "RGB666_1X18" }, >> + { MEDIA_BUS_FMT_RGB666_1X24_CPADHI, "RGB666_1X24_CPADHI" }, >> + { MEDIA_BUS_FMT_RGB666_1X7X3_SPWG, "RGB666_1X7X3_SPWG" }, >> + { MEDIA_BUS_FMT_YUV8_1X24, "YUV8_1X24" }, >> + { MEDIA_BUS_FMT_UYYVYY8_0_5X24, "UYYVYY8_0_5X24" }, >> + { MEDIA_BUS_FMT_YUV10_1X30, "YUV10_1X30" }, >> + { MEDIA_BUS_FMT_UYYVYY10_0_5X30, "UYYVYY10_0_5X30" }, >> + { MEDIA_BUS_FMT_RGB888_3X8, "RGB888_3X8" }, >> + { MEDIA_BUS_FMT_RGB888_1X24, "RGB888_1X24" }, >> + { MEDIA_BUS_FMT_RGB888_1X7X4_SPWG, "RGB888_1X7X4_SPWG" }, >> + { MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA, "RGB888_1X7X4_JEIDA" }, >> + { MEDIA_BUS_FMT_UYVY8_2X8, "UYVY8_2X8" }, >> + { MEDIA_BUS_FMT_YUYV8_1X16, "YUYV8_1X16" }, >> + { MEDIA_BUS_FMT_UYVY8_1X16, "UYVY8_1X16" }, >> + { MEDIA_BUS_FMT_RGB101010_1X30, "RGB101010_1X30" }, >> + { MEDIA_BUS_FMT_YUYV10_1X20, "YUYV10_1X20" }, >> +}; >> +static DRM_ENUM_NAME_FN(drm_get_bus_format_name, drm_bus_format_enum_list) >> + >> static const struct regmap_config vop2_regmap_config; >> >> static struct vop2_video_port *to_vop2_video_port(struct drm_crtc *crtc) >> @@ -2487,6 +2527,363 @@ static const struct drm_crtc_helper_funcs vop2_crtc_helper_funcs = { >> .atomic_disable = vop2_crtc_atomic_disable, >> }; >> >> +static void vop2_dump_connector_on_crtc(struct drm_crtc *crtc, struct seq_file *s) >> +{ >> + struct drm_connector_list_iter conn_iter; >> + struct drm_connector *connector; >> + >> + drm_connector_list_iter_begin(crtc->dev, &conn_iter); >> + drm_for_each_connector_iter(connector, &conn_iter) { >> + if (crtc->state->connector_mask & drm_connector_mask(connector)) >> + seq_printf(s, " Connector: %s\n", connector->name); >> + >> + } >> + drm_connector_list_iter_end(&conn_iter); >> +} >> + >> +static int vop2_plane_state_dump(struct seq_file *s, struct drm_plane *plane) >> +{ >> + struct vop2_win *win = to_vop2_win(plane); >> + struct drm_plane_state *pstate = plane->state; >> + struct drm_rect *src, *dst; >> + struct drm_framebuffer *fb; >> + struct drm_gem_object *obj; >> + struct rockchip_gem_object *rk_obj; >> + bool xmirror; >> + bool ymirror; >> + bool rotate_270; >> + bool rotate_90; >> + dma_addr_t fb_addr; >> + int i; >> + >> + seq_printf(s, " %s: %s\n", win->data->name, pstate->crtc ? "ACTIVE" : "DISABLED"); >> + if (!pstate || !pstate->fb) >> + return 0; >> + >> + fb = pstate->fb; >> + src = &pstate->src; >> + dst = &pstate->dst; >> + xmirror = pstate->rotation & DRM_MODE_REFLECT_X ? true : false; >> + ymirror = pstate->rotation & DRM_MODE_REFLECT_Y ? true : false; >> + rotate_270 = pstate->rotation & DRM_MODE_ROTATE_270; >> + rotate_90 = pstate->rotation & DRM_MODE_ROTATE_90; >> + >> + seq_printf(s, "\twin_id: %d\n", win->win_id); >> + >> + seq_printf(s, "\tformat: %p4cc%s glb_alpha[0x%x]\n", >> + &fb->format->format, >> + drm_is_afbc(fb->modifier) ? "[AFBC]" : "", >> + pstate->alpha >> 8); >> + seq_printf(s, "\trotate: xmirror: %d ymirror: %d rotate_90: %d rotate_270: %d\n", >> + xmirror, ymirror, rotate_90, rotate_270); >> + seq_printf(s, "\tzpos: %d\n", pstate->normalized_zpos); >> + seq_printf(s, "\tsrc: pos[%d, %d] rect[%d x %d]\n", src->x1 >> 16, >> + src->y1 >> 16, drm_rect_width(src) >> 16, >> + drm_rect_height(src) >> 16); >> + seq_printf(s, "\tdst: pos[%d, %d] rect[%d x %d]\n", dst->x1, dst->y1, >> + drm_rect_width(dst), drm_rect_height(dst)); >> + >> + for (i = 0; i < fb->format->num_planes; i++) { >> + obj = fb->obj[0]; >> + rk_obj = to_rockchip_obj(obj); >> + fb_addr = rk_obj->dma_addr + fb->offsets[0]; >> + >> + seq_printf(s, "\tbuf[%d]: addr: %pad pitch: %d offset: %d\n", >> + i, &fb_addr, fb->pitches[i], fb->offsets[i]); >> + } >> + >> + return 0; >> +} >> + >> +static int vop2_crtc_state_dump(struct drm_crtc *crtc, struct seq_file *s) >> +{ >> + struct vop2_video_port *vp = to_vop2_video_port(crtc); >> + struct drm_crtc_state *cstate = crtc->state; >> + struct rockchip_crtc_state *vcstate; >> + struct drm_display_mode *mode; >> + struct drm_plane *plane; >> + bool interlaced; >> + >> + seq_printf(s, "Video Port%d: %s\n", vp->id, !cstate ? >> + "DISABLED" : cstate->active ? "ACTIVE" : "DISABLED"); >> + >> + if (!cstate || !cstate->active) >> + return 0; >> + >> + mode = &crtc->state->adjusted_mode; >> + vcstate = to_rockchip_crtc_state(cstate); >> + interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE); >> + >> + vop2_dump_connector_on_crtc(crtc, s); >> + seq_printf(s, "\tbus_format[%x]: %s\n", vcstate->bus_format, >> + drm_get_bus_format_name(vcstate->bus_format)); >> + seq_printf(s, "\toutput_mode[%x]", vcstate->output_mode); >> + seq_printf(s, " color_space[%d]\n", vcstate->color_space); >> + seq_printf(s, " Display mode: %dx%d%s%d\n", >> + mode->hdisplay, mode->vdisplay, interlaced ? "i" : "p", >> + drm_mode_vrefresh(mode)); >> + seq_printf(s, "\tclk[%d] real_clk[%d] type[%x] flag[%x]\n", >> + mode->clock, mode->crtc_clock, mode->type, mode->flags); >> + seq_printf(s, "\tH: %d %d %d %d\n", mode->hdisplay, mode->hsync_start, >> + mode->hsync_end, mode->htotal); >> + seq_printf(s, "\tV: %d %d %d %d\n", mode->vdisplay, mode->vsync_start, >> + mode->vsync_end, mode->vtotal); >> + >> + drm_atomic_crtc_for_each_plane(plane, crtc) { >> + vop2_plane_state_dump(s, plane); >> + } >> + >> + return 0; >> +} >> + >> +static int vop2_summary_show(struct seq_file *s, void *data) >> +{ >> + struct drm_info_node *node = s->private; >> + struct drm_minor *minor = node->minor; >> + struct drm_device *drm_dev = minor->dev; >> + struct drm_crtc *crtc; >> + >> + drm_modeset_lock_all(drm_dev); >> + drm_for_each_crtc(crtc, drm_dev) { >> + vop2_crtc_state_dump(crtc, s); >> + } >> + drm_modeset_unlock_all(drm_dev); >> + >> + return 0; >> +} >> + >> +static void vop2_regs_print(struct vop2 *vop2, struct seq_file *s, struct vop2_regs_dump *dump) >> +{ >> + resource_size_t start; >> + const int reg_num = 0x110 / 4; >> >> If I'm not mistaken this prints a register space of 0x110 bytes. >> Shouldn't it be 0x100 bytes instead? >> >> Also, are all these register spaces really have the same size? Does it >> make sense to add the size to struct vop2_regs_dump? >> >> In fact, most used registers of the most blocks are not more than 100, but >> for Cluster windows, >> >> there is a CLUSTER_CTRL register sting at 0x100. >> >> I think i should add the size to struct vop2_regs_dump. >> >> >> + u32 val; >> + int i; >> + >> + if (dump->en_mask) { >> + val = vop2_readl(vop2, dump->base + dump->en_reg); >> + if ((val & dump->en_mask) != dump->en_val) >> + return; >> + } >> + seq_printf(s, "\n%s:\n", dump->name); >> + >> + start = vop2->res->start + dump->base; >> + for (i = 0; i < reg_num;) { >> + seq_printf(s, "%08x: %08x %08x %08x %08x\n", (u32)start + i * 4, >> + vop2_readl(vop2, dump->base + (4 * i)), >> + vop2_readl(vop2, dump->base + (4 * (i + 1))), >> + vop2_readl(vop2, dump->base + (4 * (i + 2))), >> + vop2_readl(vop2, dump->base + (4 * (i + 3)))); >> + i += 4; >> + } >> + >> +} >> + >> +static int vop2_regs_show(struct seq_file *s, void *arg) >> +{ >> + struct drm_info_node *node = s->private; >> + struct vop2 *vop2 = (struct vop2 *)node->info_ent->data; >> + struct drm_minor *minor = node->minor; >> + struct drm_device *drm_dev = minor->dev; >> + >> + struct vop2_regs_dump dump; >> + >> + drm_modeset_lock_all(drm_dev); >> + >> + if (vop2->enable_count) { >> + dump.en_mask = 0; >> + >> + dump.name = "SYS"; >> + dump.base = RK3568_REG_CFG_DONE; >> + vop2_regs_print(vop2, s, &dump); >> >> Can you create a statically initialized array of struct vop2_regs_dump >> and iterate over it? >> You would need an additional present_in_soc_xy flag in struct >> vop2_regs_dump, but other than that I don't see a problem and the result >> might look better. >> >> For the windows it might also be an option to iterate over >> vop2->data->win instead. This array already contains the register base >> addresses and window names. >> >> In fact, we have a dump_regs  arrar in vop2_data per soc in our bsp >> kernel[0], >> >> do you like something like that? >> >> [0] >> [3]https://github.com/armbian/linux-rockchip/blob/rk-5.10-rkr6/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c#L3684 > > This looks good from a first glance. I would suggest using C99 > initializers though. Thanks for your reply, but am not quiet claer about the C99 initializers, would you plase make it more specific, or give some example ? > >> Not sure if we really need an additional debugfs entry to print only the >> active entities, but if we do then we could avoid a bit of code >> duplication by adding creating a common register dump function called >> from vop2_regs_show() and vop2_active_regs_show() which takes an >> additional ignore_disabled argument. >> >> As the whole vop2 registers block is very large, so some times only dump >> >> active modules make we dig bugs easier. >> >> It seems that if we  "initialized array of struct vop2_regs_dump" as you >> said befor, we can avoid >> >> some duplication code here? > > Yes. > > Sascha >