diff mbox series

[5/5] drm/nouveau: Add drm_panic support for nv50+

Message ID 20240523130955.428233-6-jfalempe@redhat.com (mailing list archive)
State New, archived
Headers show
Series drm/nouveau: Add drm_panic support for nv50+ | expand

Commit Message

Jocelyn Falempe May 23, 2024, 1 p.m. UTC
Add drm_panic support, for nv50+ cards.
It's enough to get the panic screen while running Gnome/Wayland on a
GTX 1650.
It doesn't support multi-plane or compressed format.
Support for other formats and older cards will come later.
Tiling is only tested on GTX1650, and might be wrong for other cards.

Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
---
 drivers/gpu/drm/nouveau/dispnv50/wndw.c | 127 +++++++++++++++++++++++-
 1 file changed, 125 insertions(+), 2 deletions(-)

Comments

kernel test robot May 24, 2024, 10:53 a.m. UTC | #1
Hi Jocelyn,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 484436ec5c2bffe8f346a09ae1cbc4cbf5e50005]

url:    https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-panic-Add-ABGR2101010-support/20240523-211335
base:   484436ec5c2bffe8f346a09ae1cbc4cbf5e50005
patch link:    https://lore.kernel.org/r/20240523130955.428233-6-jfalempe%40redhat.com
patch subject: [PATCH 5/5] drm/nouveau: Add drm_panic support for nv50+
config: x86_64-randconfig-r113-20240524 (https://download.01.org/0day-ci/archive/20240524/202405241832.ETpErbon-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240524/202405241832.ETpErbon-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405241832.ETpErbon-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/nouveau/dispnv50/wndw.c:675:66: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void [noderef] __iomem *vaddr_iomem @@     got void *virtual @@
   drivers/gpu/drm/nouveau/dispnv50/wndw.c:675:66: sparse:     expected void [noderef] __iomem *vaddr_iomem
   drivers/gpu/drm/nouveau/dispnv50/wndw.c:675:66: sparse:     got void *virtual
   drivers/gpu/drm/nouveau/dispnv50/wndw.c: note: in included file (through include/linux/timer.h, include/linux/workqueue.h, drivers/gpu/drm/nouveau/dispnv50/disp.h, ...):
   include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true

vim +675 drivers/gpu/drm/nouveau/dispnv50/wndw.c

   652	
   653	static int
   654	nv50_wndw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
   655	{
   656		struct drm_framebuffer *fb;
   657		struct nouveau_bo *nvbo;
   658	
   659		if (!plane->state || !plane->state->fb)
   660			return -EINVAL;
   661	
   662		fb = plane->state->fb;
   663		nvbo = nouveau_gem_object(fb->obj[0]);
   664	
   665		/* Don't support compressed format, or multiplane yet */
   666		if (nvbo->comp || fb->format->num_planes != 1)
   667			return -EOPNOTSUPP;
   668	
   669		if (nouveau_bo_map(nvbo)) {
   670			pr_warn("nouveau bo map failed, panic won't be displayed\n");
   671			return -ENOMEM;
   672		}
   673	
   674		if (nvbo->kmap.bo_kmap_type & TTM_BO_MAP_IOMEM_MASK)
 > 675			iosys_map_set_vaddr_iomem(&sb->map[0], nvbo->kmap.virtual);
   676		else
   677			iosys_map_set_vaddr(&sb->map[0], nvbo->kmap.virtual);
   678	
   679		sb->height = fb->height;
   680		sb->width = fb->width;
   681		sb->pitch[0] = fb->pitches[0];
   682		sb->format = fb->format;
   683	
   684		/* If tiling is enabled, use the set_pixel() to display correctly */
   685		if (fb->modifier & 0xf) {
   686			sb->private = (void *) fb;
   687			sb->set_pixel = nv50_set_pixel;
   688		}
   689		return 0;
   690	}
   691
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/dispnv50/wndw.c b/drivers/gpu/drm/nouveau/dispnv50/wndw.c
index 7a2cceaee6e9..dd7aafb9198a 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/wndw.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/wndw.c
@@ -30,11 +30,16 @@ 
 #include <nvhw/class/cl507e.h>
 #include <nvhw/class/clc37e.h>
 
+#include <linux/iosys-map.h>
+
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_blend.h>
-#include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_fourcc.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_gem_atomic_helper.h>
+#include <drm/drm_panic.h>
+#include <drm/ttm/ttm_bo.h>
 
 #include "nouveau_bo.h"
 #include "nouveau_gem.h"
@@ -577,6 +582,113 @@  nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state)
 	return 0;
 }
 
+/* Values found on GTX1650 */
+/* blocks level 0, 4x4 pixels */
+#define BL0_W 4
+/* blocks level 1, 8x8 pixels */
+#define BL1_W 8
+/* blocks level 2, Group of Bytes? 16x128 pixels */
+#define BL2_W 16
+
+/* get the offset in bytes inside the framebuffer, after taking tiling into account */
+static unsigned int nv50_get_tiled_offset(struct drm_scanout_buffer *sb, unsigned int gobs,
+					  unsigned int x, unsigned int y, unsigned int px_width)
+{
+	u32 blk2_x, blk2_y, bl2sz;
+	u32 blk1_x, blk1_y, bl1sz;
+	u32 blk0_x, blk0_y, bl0sz;
+	u32 nblk2w, bl2_h, off;
+
+	/* fixme - block2 height depends of the "Group of Bytes" value */
+	bl2_h = BL1_W * gobs;
+
+	bl0sz = BL0_W * BL0_W * px_width;
+	bl1sz = BL1_W * BL1_W * px_width;
+	bl2sz = BL2_W * bl2_h * px_width;
+
+	/* block level 2 coordinate */
+	blk2_x = x / BL2_W;
+	blk2_y = y / bl2_h;
+
+	x = x % BL2_W;
+	y = y % bl2_h;
+
+	/* block level 1 coordinate */
+	blk1_x = x / BL1_W;
+	blk1_y = y / BL1_W;
+
+	x = x % BL1_W;
+	y = y % BL1_W;
+
+	/* block level 0 coordinate */
+	blk0_x = x / BL0_W;
+	blk0_y = y / BL0_W;
+
+	x = x % BL0_W;
+	y = y % BL0_W;
+
+	nblk2w = DIV_ROUND_UP(sb->width, BL2_W);
+
+	off = ((blk2_y * nblk2w) + blk2_x) * bl2sz;
+	off += ((blk1_y * 2) + blk1_x) * bl1sz;
+	off += (blk0_y * 2 + blk0_x) * bl0sz;
+	off += (x + y * BL0_W) * px_width;
+
+	return off;
+}
+
+static void nv50_set_pixel(struct drm_scanout_buffer *sb, unsigned int x, unsigned int y, u32 color)
+{
+	struct drm_framebuffer *fb = sb->private;
+	unsigned int off;
+	/* According to DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D documentation,
+	 * the last 4 bits of modifier is log2(height) of each block, in GOBs
+	 */
+	unsigned int gobs = 1 << (fb->modifier & 0xf);
+
+	off = nv50_get_tiled_offset(sb, gobs, x, y, sb->format->cpp[0]);
+	iosys_map_wr(&sb->map[0], off, u32, color);
+}
+
+static int
+nv50_wndw_get_scanout_buffer(struct drm_plane *plane, struct drm_scanout_buffer *sb)
+{
+	struct drm_framebuffer *fb;
+	struct nouveau_bo *nvbo;
+
+	if (!plane->state || !plane->state->fb)
+		return -EINVAL;
+
+	fb = plane->state->fb;
+	nvbo = nouveau_gem_object(fb->obj[0]);
+
+	/* Don't support compressed format, or multiplane yet */
+	if (nvbo->comp || fb->format->num_planes != 1)
+		return -EOPNOTSUPP;
+
+	if (nouveau_bo_map(nvbo)) {
+		pr_warn("nouveau bo map failed, panic won't be displayed\n");
+		return -ENOMEM;
+	}
+
+	if (nvbo->kmap.bo_kmap_type & TTM_BO_MAP_IOMEM_MASK)
+		iosys_map_set_vaddr_iomem(&sb->map[0], nvbo->kmap.virtual);
+	else
+		iosys_map_set_vaddr(&sb->map[0], nvbo->kmap.virtual);
+
+	sb->height = fb->height;
+	sb->width = fb->width;
+	sb->pitch[0] = fb->pitches[0];
+	sb->format = fb->format;
+
+	/* If tiling is enabled, use the set_pixel() to display correctly */
+	if (fb->modifier & 0xf) {
+		sb->private = (void *) fb;
+		sb->set_pixel = nv50_set_pixel;
+	}
+	return 0;
+}
+
 static const struct drm_plane_helper_funcs
 nv50_wndw_helper = {
 	.prepare_fb = nv50_wndw_prepare_fb,
@@ -584,6 +696,14 @@  nv50_wndw_helper = {
 	.atomic_check = nv50_wndw_atomic_check,
 };
 
+static const struct drm_plane_helper_funcs
+nv50_wndw_primary_helper = {
+	.prepare_fb = nv50_wndw_prepare_fb,
+	.cleanup_fb = nv50_wndw_cleanup_fb,
+	.atomic_check = nv50_wndw_atomic_check,
+	.get_scanout_buffer = nv50_wndw_get_scanout_buffer,
+};
+
 static void
 nv50_wndw_atomic_destroy_state(struct drm_plane *plane,
 			       struct drm_plane_state *state)
@@ -732,7 +852,10 @@  nv50_wndw_new_(const struct nv50_wndw_func *func, struct drm_device *dev,
 		return ret;
 	}
 
-	drm_plane_helper_add(&wndw->plane, &nv50_wndw_helper);
+	if (type == DRM_PLANE_TYPE_PRIMARY)
+		drm_plane_helper_add(&wndw->plane, &nv50_wndw_primary_helper);
+	else
+		drm_plane_helper_add(&wndw->plane, &nv50_wndw_helper);
 
 	if (wndw->func->ilut) {
 		ret = nv50_lut_init(disp, mmu, &wndw->ilut);