From patchwork Fri May 31 08:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jocelyn Falempe X-Patchwork-Id: 13681291 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BA65BC25B75 for ; Fri, 31 May 2024 08:08:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D7AEF10EF16; Fri, 31 May 2024 08:08:33 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="HwgyRvkR"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id F25B71136D6 for ; Fri, 31 May 2024 08:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717142906; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Noz5/Cq7B48TTwvYOq18m2v7kLGAGmxTvOAWczyRKFo=; b=HwgyRvkRv8gXsVSLZ+spqSPYKgWv9gW2wcz5cw6dCapdQmaepC8KELeytZk1fZJGLpuHXc /iMFtqrhg7LwXdBSr5p2QDRwbQ33UViRQx69sZD1Ei0s3XibYierHPn9ga5g0VQRl/GqRi WkSOQ27P2ba7EXnek1Fs2kyZJJCYXZk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-zFB9qjD1OH2JC9wfoLL8fw-1; Fri, 31 May 2024 04:08:19 -0400 X-MC-Unique: zFB9qjD1OH2JC9wfoLL8fw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B940101A54F; Fri, 31 May 2024 08:08:19 +0000 (UTC) Received: from hydra.redhat.com (unknown [10.39.193.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 065CB4B400E; Fri, 31 May 2024 08:08:17 +0000 (UTC) From: Jocelyn Falempe To: dri-devel@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: Jocelyn Falempe Subject: [PATCH 1/3] drm/panic: only draw the foreground color in drm_panic_blit() Date: Fri, 31 May 2024 10:06:32 +0200 Message-ID: <20240531080750.765982-2-jfalempe@redhat.com> In-Reply-To: <20240531080750.765982-1-jfalempe@redhat.com> References: <20240531080750.765982-1-jfalempe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The whole framebuffer is cleared, so it's useless to rewrite the background colored pixels. It allows to simplify the drawing functions, and prepare the work for the set_pixel() callback. Signed-off-by: Jocelyn Falempe Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/drm_panic.c | 63 +++++++++++++++---------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c index 7ece67086cec..9d95c7eaae83 100644 --- a/drivers/gpu/drm/drm_panic.c +++ b/drivers/gpu/drm/drm_panic.c @@ -197,37 +197,33 @@ static u32 convert_from_xrgb8888(u32 color, u32 format) static void drm_panic_blit16(struct iosys_map *dmap, unsigned int dpitch, const u8 *sbuf8, unsigned int spitch, unsigned int height, unsigned int width, - u16 fg16, u16 bg16) + u16 color) { unsigned int y, x; - u16 val16; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - val16 = (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) ? fg16 : bg16; - iosys_map_wr(dmap, y * dpitch + x * sizeof(u16), u16, val16); - } - } + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) + if (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) + iosys_map_wr(dmap, y * dpitch + x * sizeof(u16), u16, color); } static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch, const u8 *sbuf8, unsigned int spitch, unsigned int height, unsigned int width, - u32 fg32, u32 bg32) + u32 color) { unsigned int y, x; - u32 val32; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { u32 off = y * dpitch + x * 3; - val32 = (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) ? fg32 : bg32; - - /* write blue-green-red to output in little endianness */ - iosys_map_wr(dmap, off, u8, (val32 & 0x000000FF) >> 0); - iosys_map_wr(dmap, off + 1, u8, (val32 & 0x0000FF00) >> 8); - iosys_map_wr(dmap, off + 2, u8, (val32 & 0x00FF0000) >> 16); + if (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) { + /* write blue-green-red to output in little endianness */ + iosys_map_wr(dmap, off, u8, (color & 0x000000FF) >> 0); + iosys_map_wr(dmap, off + 1, u8, (color & 0x0000FF00) >> 8); + iosys_map_wr(dmap, off + 2, u8, (color & 0x00FF0000) >> 16); + } } } } @@ -235,17 +231,14 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch, static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch, const u8 *sbuf8, unsigned int spitch, unsigned int height, unsigned int width, - u32 fg32, u32 bg32) + u32 color) { unsigned int y, x; - u32 val32; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - val32 = (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) ? fg32 : bg32; - iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, val32); - } - } + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) + if (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) + iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, color); } /* @@ -256,8 +249,7 @@ static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch, * @spitch: source pitch in bytes * @height: height of the image to copy, in pixels * @width: width of the image to copy, in pixels - * @fg_color: foreground color, in destination format - * @bg_color: background color, in destination format + * @color: foreground color, in destination format * @pixel_width: pixel width in bytes. * * This can be used to draw a font character, which is a monochrome image, to a @@ -266,21 +258,20 @@ static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch, static void drm_panic_blit(struct iosys_map *dmap, unsigned int dpitch, const u8 *sbuf8, unsigned int spitch, unsigned int height, unsigned int width, - u32 fg_color, u32 bg_color, - unsigned int pixel_width) + u32 color, unsigned int pixel_width) { switch (pixel_width) { case 2: drm_panic_blit16(dmap, dpitch, sbuf8, spitch, - height, width, fg_color, bg_color); + height, width, color); break; case 3: drm_panic_blit24(dmap, dpitch, sbuf8, spitch, - height, width, fg_color, bg_color); + height, width, color); break; case 4: drm_panic_blit32(dmap, dpitch, sbuf8, spitch, - height, width, fg_color, bg_color); + height, width, color); break; default: WARN_ONCE(1, "Can't blit with pixel width %d\n", pixel_width); @@ -381,8 +372,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb, unsigned int msg_lines, bool centered, struct drm_rect *clip, - u32 fg_color, - u32 bg_color) + u32 color) { int i, j; const u8 *src; @@ -404,8 +394,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb, for (j = 0; j < line_len; j++) { src = get_char_bitmap(font, msg[i].txt[j], font_pitch); drm_panic_blit(&dst, sb->pitch[0], src, font_pitch, - font->height, font->width, - fg_color, bg_color, px_width); + font->height, font->width, color, px_width); iosys_map_incr(&dst, font->width * px_width); } } @@ -445,9 +434,9 @@ static void draw_panic_static(struct drm_scanout_buffer *sb) if ((r_msg.x1 >= drm_rect_width(&r_logo) || r_msg.y1 >= drm_rect_height(&r_logo)) && drm_rect_width(&r_logo) < sb->width && drm_rect_height(&r_logo) < sb->height) { - draw_txt_rectangle(sb, font, logo, logo_lines, false, &r_logo, fg_color, bg_color); + draw_txt_rectangle(sb, font, logo, logo_lines, false, &r_logo, fg_color); } - draw_txt_rectangle(sb, font, panic_msg, msg_lines, true, &r_msg, fg_color, bg_color); + draw_txt_rectangle(sb, font, panic_msg, msg_lines, true, &r_msg, fg_color); } /* From patchwork Fri May 31 08:06:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jocelyn Falempe X-Patchwork-Id: 13681288 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B1F5DC25B75 for ; Fri, 31 May 2024 08:08:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3C15113249; Fri, 31 May 2024 08:08:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="ZBWHrwNq"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5DA1111352D for ; Fri, 31 May 2024 08:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717142904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/soml8FAMcfJeklG6pBeKlCKu2fzh07f7rLuMOYOmcg=; b=ZBWHrwNqQUSk6kO7OQ3kZ+9zi/irOIqO5+HXrgOPykeZxO+BbDGMx/U+jwjSxfAB3TModL lE+/0ksc6BTwzP6JWO7aWdfs5sBhCIdeyQl/Aj5bfja1F7Et2A7sE7KPGvDQXRefHEDgAC LQzo+Tm/ffCeIpdr5UuCmDJR0+7FI2U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407-ELeDlVJbMPuV-f0p_b78vg-1; Fri, 31 May 2024 04:08:20 -0400 X-MC-Unique: ELeDlVJbMPuV-f0p_b78vg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4464C3806701; Fri, 31 May 2024 08:08:20 +0000 (UTC) Received: from hydra.redhat.com (unknown [10.39.193.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FA0A40EFD4; Fri, 31 May 2024 08:08:19 +0000 (UTC) From: Jocelyn Falempe To: dri-devel@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: Jocelyn Falempe Subject: [PATCH 2/3] drm/panic: Add a set_pixel() callback to drm_scanout_buffer Date: Fri, 31 May 2024 10:06:33 +0200 Message-ID: <20240531080750.765982-3-jfalempe@redhat.com> In-Reply-To: <20240531080750.765982-1-jfalempe@redhat.com> References: <20240531080750.765982-1-jfalempe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This allows drivers to draw the pixel, and handle tiling, or specific color formats. Signed-off-by: Jocelyn Falempe Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/drm_panic.c | 120 +++++++++++++++++++++++------------- include/drm/drm_panic.h | 9 +++ 2 files changed, 85 insertions(+), 44 deletions(-) diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c index 9d95c7eaae83..27e26b9d842c 100644 --- a/drivers/gpu/drm/drm_panic.c +++ b/drivers/gpu/drm/drm_panic.c @@ -241,40 +241,54 @@ static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch, iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, color); } +static void drm_panic_blit_pixel(struct drm_scanout_buffer *sb, struct drm_rect *clip, + const u8 *sbuf8, unsigned int spitch, u32 color) +{ + unsigned int y, x; + + for (y = 0; y < drm_rect_height(clip); y++) + for (x = 0; x < drm_rect_width(clip); x++) + if (sbuf8[(y * spitch) + x / 8] & (0x80 >> (x % 8))) + sb->set_pixel(sb, clip->x1 + x, clip->y1 + y, color); +} + /* * drm_panic_blit - convert a monochrome image to a linear framebuffer - * @dmap: destination iosys_map - * @dpitch: destination pitch in bytes + * @sb: destination scanout buffer + * @clip: destination rectangle * @sbuf8: source buffer, in monochrome format, 8 pixels per byte. * @spitch: source pitch in bytes - * @height: height of the image to copy, in pixels - * @width: width of the image to copy, in pixels * @color: foreground color, in destination format - * @pixel_width: pixel width in bytes. * * This can be used to draw a font character, which is a monochrome image, to a * framebuffer in other supported format. */ -static void drm_panic_blit(struct iosys_map *dmap, unsigned int dpitch, - const u8 *sbuf8, unsigned int spitch, - unsigned int height, unsigned int width, - u32 color, unsigned int pixel_width) +static void drm_panic_blit(struct drm_scanout_buffer *sb, struct drm_rect *clip, + const u8 *sbuf8, unsigned int spitch, u32 color) { - switch (pixel_width) { + struct iosys_map map; + + if (sb->set_pixel) + return drm_panic_blit_pixel(sb, clip, sbuf8, spitch, color); + + map = sb->map[0]; + iosys_map_incr(&map, clip->y1 * sb->pitch[0] + clip->x1 * sb->format->cpp[0]); + + switch (sb->format->cpp[0]) { case 2: - drm_panic_blit16(dmap, dpitch, sbuf8, spitch, - height, width, color); + drm_panic_blit16(&map, sb->pitch[0], sbuf8, spitch, + drm_rect_height(clip), drm_rect_width(clip), color); break; case 3: - drm_panic_blit24(dmap, dpitch, sbuf8, spitch, - height, width, color); + drm_panic_blit24(&map, sb->pitch[0], sbuf8, spitch, + drm_rect_height(clip), drm_rect_width(clip), color); break; case 4: - drm_panic_blit32(dmap, dpitch, sbuf8, spitch, - height, width, color); + drm_panic_blit32(&map, sb->pitch[0], sbuf8, spitch, + drm_rect_height(clip), drm_rect_width(clip), color); break; default: - WARN_ONCE(1, "Can't blit with pixel width %d\n", pixel_width); + WARN_ONCE(1, "Can't blit with pixel width %d\n", sb->format->cpp[0]); } } @@ -318,33 +332,51 @@ static void drm_panic_fill32(struct iosys_map *dmap, unsigned int dpitch, iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, color); } +static void drm_panic_fill_pixel(struct drm_scanout_buffer *sb, + struct drm_rect *clip, + u32 color) +{ + unsigned int y, x; + + for (y = 0; y < drm_rect_height(clip); y++) + for (x = 0; x < drm_rect_width(clip); x++) + sb->set_pixel(sb, clip->x1 + x, clip->y1 + y, color); +} + /* * drm_panic_fill - Fill a rectangle with a color - * @dmap: destination iosys_map, pointing to the top left corner of the rectangle - * @dpitch: destination pitch in bytes - * @height: height of the rectangle, in pixels - * @width: width of the rectangle, in pixels - * @color: color to fill the rectangle. - * @pixel_width: pixel width in bytes + * @sb: destination scanout buffer + * @clip: destination rectangle + * @color: foreground color, in destination format * * Fill a rectangle with a color, in a linear framebuffer. */ -static void drm_panic_fill(struct iosys_map *dmap, unsigned int dpitch, - unsigned int height, unsigned int width, - u32 color, unsigned int pixel_width) +static void drm_panic_fill(struct drm_scanout_buffer *sb, struct drm_rect *clip, + u32 color) { - switch (pixel_width) { + struct iosys_map map; + + if (sb->set_pixel) + return drm_panic_fill_pixel(sb, clip, color); + + map = sb->map[0]; + iosys_map_incr(&map, clip->y1 * sb->pitch[0] + clip->x1 * sb->format->cpp[0]); + + switch (sb->format->cpp[0]) { case 2: - drm_panic_fill16(dmap, dpitch, height, width, color); + drm_panic_fill16(&map, sb->pitch[0], drm_rect_height(clip), + drm_rect_width(clip), color); break; case 3: - drm_panic_fill24(dmap, dpitch, height, width, color); + drm_panic_fill24(&map, sb->pitch[0], drm_rect_height(clip), + drm_rect_width(clip), color); break; case 4: - drm_panic_fill32(dmap, dpitch, height, width, color); + drm_panic_fill32(&map, sb->pitch[0], drm_rect_height(clip), + drm_rect_width(clip), color); break; default: - WARN_ONCE(1, "Can't fill with pixel width %d\n", pixel_width); + WARN_ONCE(1, "Can't fill with pixel width %d\n", sb->format->cpp[0]); } } @@ -377,25 +409,24 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb, int i, j; const u8 *src; size_t font_pitch = DIV_ROUND_UP(font->width, 8); - struct iosys_map dst; - unsigned int px_width = sb->format->cpp[0]; - int left = 0; + struct drm_rect rec; msg_lines = min(msg_lines, drm_rect_height(clip) / font->height); for (i = 0; i < msg_lines; i++) { size_t line_len = min(msg[i].len, drm_rect_width(clip) / font->width); + rec.y1 = clip->y1 + i * font->height; + rec.y2 = rec.y1 + font->height; + rec.x1 = clip->x1; + if (centered) - left = (drm_rect_width(clip) - (line_len * font->width)) / 2; + rec.x1 += (drm_rect_width(clip) - (line_len * font->width)) / 2; - dst = sb->map[0]; - iosys_map_incr(&dst, (clip->y1 + i * font->height) * sb->pitch[0] + - (clip->x1 + left) * px_width); for (j = 0; j < line_len; j++) { src = get_char_bitmap(font, msg[i].txt[j], font_pitch); - drm_panic_blit(&dst, sb->pitch[0], src, font_pitch, - font->height, font->width, color, px_width); - iosys_map_incr(&dst, font->width * px_width); + rec.x2 = rec.x1 + font->width; + drm_panic_blit(sb, &rec, src, font_pitch, color); + rec.x1 += font->width; } } } @@ -410,7 +441,7 @@ static void draw_panic_static(struct drm_scanout_buffer *sb) u32 fg_color = CONFIG_DRM_PANIC_FOREGROUND_COLOR; u32 bg_color = CONFIG_DRM_PANIC_BACKGROUND_COLOR; const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL); - struct drm_rect r_logo, r_msg; + struct drm_rect r_screen, r_logo, r_msg; if (!font) return; @@ -418,6 +449,8 @@ static void draw_panic_static(struct drm_scanout_buffer *sb) fg_color = convert_from_xrgb8888(fg_color, sb->format->format); bg_color = convert_from_xrgb8888(bg_color, sb->format->format); + r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height); + r_logo = DRM_RECT_INIT(0, 0, get_max_line_len(logo, logo_lines) * font->width, logo_lines * font->height); @@ -429,8 +462,7 @@ static void draw_panic_static(struct drm_scanout_buffer *sb) drm_rect_translate(&r_msg, (sb->width - r_msg.x2) / 2, (sb->height - r_msg.y2) / 2); /* Fill with the background color, and draw text on top */ - drm_panic_fill(&sb->map[0], sb->pitch[0], sb->height, sb->width, - bg_color, sb->format->cpp[0]); + drm_panic_fill(sb, &r_screen, bg_color); if ((r_msg.x1 >= drm_rect_width(&r_logo) || r_msg.y1 >= drm_rect_height(&r_logo)) && drm_rect_width(&r_logo) < sb->width && drm_rect_height(&r_logo) < sb->height) { diff --git a/include/drm/drm_panic.h b/include/drm/drm_panic.h index 822dbb1aa9d6..73bb3f3d9ed9 100644 --- a/include/drm/drm_panic.h +++ b/include/drm/drm_panic.h @@ -50,6 +50,15 @@ struct drm_scanout_buffer { * @pitch: Length in bytes between the start of two consecutive lines. */ unsigned int pitch[DRM_FORMAT_MAX_PLANES]; + + /** + * @set_pixel: Optional function, to set a pixel color on the + * framebuffer. It allows to handle special tiling format inside the + * driver. + */ + void (*set_pixel)(struct drm_scanout_buffer *sb, unsigned int x, + unsigned int y, u32 color); + }; /** From patchwork Fri May 31 08:06:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jocelyn Falempe X-Patchwork-Id: 13681289 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E712AC25B75 for ; Fri, 31 May 2024 08:08:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B873710E386; Fri, 31 May 2024 08:08:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="NhfH0xkH"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id F1E51113249 for ; Fri, 31 May 2024 08:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717142905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GQ+6H8/ksuGqaatIJSB6x2l2hNP0z56ovJDtUaraPg4=; b=NhfH0xkHMVgWP4KtU8AQOtW02p0ZFpb0q9/DP6qqZxbyhMd/ZJAb5ti4VJ5qm3eNOHB8NO nZdEIvPUcvEXLOmYc4w3cqqjUmZPf6JpLYfQ6Lfbl+v7ZZuS0SswuXpiatCpuhkZEwCmnI u7/PFVHdItVNQ748sLo6/8SqFZJI1LM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-BXynmbHQOkW_q80cnnZlow-1; Fri, 31 May 2024 04:08:21 -0400 X-MC-Unique: BXynmbHQOkW_q80cnnZlow-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7DDAB1C0512B; Fri, 31 May 2024 08:08:21 +0000 (UTC) Received: from hydra.redhat.com (unknown [10.39.193.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78AF840EFD4; Fri, 31 May 2024 08:08:20 +0000 (UTC) From: Jocelyn Falempe To: dri-devel@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: Jocelyn Falempe Subject: [PATCH 3/3] drm/panic: Add a kmsg dump screen Date: Fri, 31 May 2024 10:06:34 +0200 Message-ID: <20240531080750.765982-4-jfalempe@redhat.com> In-Reply-To: <20240531080750.765982-1-jfalempe@redhat.com> References: <20240531080750.765982-1-jfalempe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a kmsg dump option, which will display the last lines of kmsg, and should be similar to fbcon. Add a Kconfig choice for the panic screen, so that the user can choose between this new kmsg dump, or the userfriendly option. Signed-off-by: Jocelyn Falempe Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/Kconfig | 21 +++++ drivers/gpu/drm/drm_panic.c | 151 +++++++++++++++++++++++++++--------- 2 files changed, 136 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 9703429de6b9..78d401b55102 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -137,6 +137,27 @@ config DRM_PANIC_DEBUG This is unsafe and should not be enabled on a production build. If in doubt, say "N". +choice + prompt "Panic screen formater" + default DRM_PANIC_SCREEN_USERFRIENDLY + depends on DRM_PANIC + help + This option enable to choose what will be displayed when a kernel + panic occurs. + + config DRM_PANIC_SCREEN_USERFRIENDLY + bool "Default user friendly message" + help + Only a short message telling the user to reboot the system. + + config DRM_PANIC_SCREEN_KMSG + bool "Display the last lines of kmsg" + help + Display kmsg last lines on panic. + Enable if you are a kernel developer, and want to debug a + kernel panic. +endchoice + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c index 27e26b9d842c..71f6f566d64b 100644 --- a/drivers/gpu/drm/drm_panic.c +++ b/drivers/gpu/drm/drm_panic.c @@ -63,24 +63,6 @@ struct drm_panic_line { const char *txt; }; -#define PANIC_LINE(s) {.len = sizeof(s) - 1, .txt = s} - -static struct drm_panic_line panic_msg[] = { - PANIC_LINE("KERNEL PANIC !"), - PANIC_LINE(""), - PANIC_LINE("Please reboot your computer."), -}; - -static const struct drm_panic_line logo[] = { - PANIC_LINE(" .--. _"), - PANIC_LINE(" |o_o | | |"), - PANIC_LINE(" |:_/ | | |"), - PANIC_LINE(" // \\ \\ |_|"), - PANIC_LINE(" (| | ) _"), - PANIC_LINE(" /'\\_ _/`\\ (_)"), - PANIC_LINE(" \\___)=(___/"), -}; - /* * Color conversion */ @@ -385,16 +367,6 @@ static const u8 *get_char_bitmap(const struct font_desc *font, char c, size_t fo return font->data + (c * font->height) * font_pitch; } -static unsigned int get_max_line_len(const struct drm_panic_line *lines, int len) -{ - int i; - unsigned int max = 0; - - for (i = 0; i < len; i++) - max = max(lines[i].len, max); - return max; -} - /* * Draw a text in a rectangle on a framebuffer. The text is truncated if it overflows the rectangle */ @@ -431,24 +403,48 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb, } } -/* - * Draw the panic message at the center of the screen - */ +#if defined(CONFIG_DRM_PANIC_SCREEN_USERFRIENDLY) + +#define PANIC_LINE(s) {.len = sizeof(s) - 1, .txt = s} + +static struct drm_panic_line panic_msg[] = { + PANIC_LINE("KERNEL PANIC !"), + PANIC_LINE(""), + PANIC_LINE("Please reboot your computer."), +}; + +static const struct drm_panic_line logo[] = { + PANIC_LINE(" .--. _"), + PANIC_LINE(" |o_o | | |"), + PANIC_LINE(" |:_/ | | |"), + PANIC_LINE(" // \\ \\ |_|"), + PANIC_LINE(" (| | ) _"), + PANIC_LINE(" /'\\_ _/`\\ (_)"), + PANIC_LINE(" \\___)=(___/"), +}; + +static unsigned int get_max_line_len(const struct drm_panic_line *lines, int len) +{ + int i; + unsigned int max = 0; + + for (i = 0; i < len; i++) + max = max(lines[i].len, max); + return max; +} + static void draw_panic_static(struct drm_scanout_buffer *sb) { size_t msg_lines = ARRAY_SIZE(panic_msg); size_t logo_lines = ARRAY_SIZE(logo); - u32 fg_color = CONFIG_DRM_PANIC_FOREGROUND_COLOR; - u32 bg_color = CONFIG_DRM_PANIC_BACKGROUND_COLOR; + u32 fg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_FOREGROUND_COLOR, sb->format->format); + u32 bg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_BACKGROUND_COLOR, sb->format->format); const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL); struct drm_rect r_screen, r_logo, r_msg; if (!font) return; - fg_color = convert_from_xrgb8888(fg_color, sb->format->format); - bg_color = convert_from_xrgb8888(bg_color, sb->format->format); - r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height); r_logo = DRM_RECT_INIT(0, 0, @@ -471,6 +467,89 @@ static void draw_panic_static(struct drm_scanout_buffer *sb) draw_txt_rectangle(sb, font, panic_msg, msg_lines, true, &r_msg, fg_color); } +#elif defined(CONFIG_DRM_PANIC_SCREEN_KMSG) + +#include +#include + +/* + * Draw one line of kmsg, and handle wrapping if it won't fit in the screen width. + * Return the y-offset of the next line. + */ +static int draw_line_with_wrap(struct drm_scanout_buffer *sb, const struct font_desc *font, + struct drm_panic_line *line, int yoffset, u32 fg_color) +{ + int chars_per_row = sb->width / font->width; + struct drm_rect r_txt = DRM_RECT_INIT(0, yoffset, sb->width, sb->height); + struct drm_panic_line line_wrap; + + if (line->len > chars_per_row) { + line_wrap.len = line->len % chars_per_row; + line_wrap.txt = line->txt + line->len - line_wrap.len; + draw_txt_rectangle(sb, font, &line_wrap, 1, false, &r_txt, fg_color); + r_txt.y1 -= font->height; + if (r_txt.y1 < 0) + return r_txt.y1; + while (line_wrap.txt > line->txt) { + line_wrap.txt -= chars_per_row; + line_wrap.len = chars_per_row; + draw_txt_rectangle(sb, font, &line_wrap, 1, false, &r_txt, fg_color); + r_txt.y1 -= font->height; + if (r_txt.y1 < 0) + return r_txt.y1; + } + } else { + draw_txt_rectangle(sb, font, line, 1, false, &r_txt, fg_color); + r_txt.y1 -= font->height; + } + return r_txt.y1; +} + +/* + * Draw the kmsg buffer to the screen, starting from the youngest message at the bottom, + * and going up until reaching the top of the screen. + */ +static void draw_panic_static(struct drm_scanout_buffer *sb) +{ + u32 fg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_FOREGROUND_COLOR, sb->format->format); + u32 bg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_BACKGROUND_COLOR, sb->format->format); + const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL); + struct drm_rect r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height); + struct kmsg_dump_iter iter; + char kmsg_buf[512]; + size_t kmsg_len; + struct drm_panic_line line; + int yoffset = sb->height - font->height - (sb->height % font->height) / 2; + + if (!font) + return; + + /* Fill with the background color, and draw text on top */ + drm_panic_fill(sb, &r_screen, bg_color); + + kmsg_dump_rewind(&iter); + while (kmsg_dump_get_buffer(&iter, false, kmsg_buf, sizeof(kmsg_buf), &kmsg_len)) { + char *start; + char *end; + + /* ignore terminating NUL and newline */ + start = kmsg_buf + kmsg_len - 2; + end = kmsg_buf + kmsg_len - 1; + while (start > kmsg_buf && yoffset >= 0) { + while (start > kmsg_buf && *start != '\n') + start--; + /* don't count the newline character */ + line.txt = start + (start == kmsg_buf ? 0 : 1); + line.len = end - line.txt; + + yoffset = draw_line_with_wrap(sb, font, &line, yoffset, fg_color); + end = start; + start--; + } + } +} +#endif + /* * drm_panic_is_format_supported() * @format: a fourcc color code